How to query and update Child and Parent information from Child records in Salesforce?

How to query and update Child and Parent information from Child records in Salesforce?

Sample Code:

Contact c = [ SELECT Account.AccountNumber, LastName FROM Contact WHERE Id = ‘003U000001cdHIf’];
c.LastName = ‘Testing’;
c.Account.AccountNumber = ‘222’;
update c;
update c.Account;

Cheers!!!

Leave a Reply