You need to sign in to do that
Don't have an account?
Force.platform
how to update parent record of custom object using DML
Child name-Childobject__C;
Parent name-Parentobjectname__c;
i want query to update related parent record.
Parent name-Parentobjectname__c;
i want query to update related parent record.
https://success.salesforce.com/answers?id=90630000000ZggwAAC
Thanks
Lokesh
Please go through the below code
DML Code for Execute Anonymous
Childobject__c childRecord = [select Id, Name, Parentobjectname__c from Childobject__c where Parentobjectname__c != null limit 1];// Parentobjectname__c here is a Parent Object lookup field on Child Object.
Parentobjectname__c parentRecord = [select Id, Name from Parentobjectname__c where Id =: childRecord.Parentobjectname__c];
// BEFORE UPDATE //
system.debug('Child Name --- '+childRecord.Name);
system.debug('Parent Name --- '+parentRecord.Name);
parentRecord.Name = 'Updated Parent Name';
update parentRecord;
update childRecord;
// AFTER UPDATE //
system.debug('Parent Name After Updation --- '+parentRecord.Name);
system.debug('Child Name After Updation --- '+childRecord.Name);
Regards,
Akshay