Trigger to update parent records field when child record is updated | update parent field from child using apex trigger
Hey guys, today in this post we are going to learn about How to update the parent record field based on child record trigger in Salesforce custom object
Real time scenarios:- Write a trigger on custom object where update parent records field whenever child record is inserted or updated.
Create two custom object, both are associated with lookup relationship with each other
1) Custom Object:- parentObjTrigger__c custom field:- Status__c (Checkbox boolean type)
2) Custom Object:- childObjTrigger__c custom field:- Status__c (Checkbox boolean type)
If status field of child object marked true then should be status field of parent object automatic marked as true.
Files we used in this post example:-
checkboxStatus.apxt
Apex Class Trigger
It is used for update parent object field based on child records
Custom Parent Object:- parentObjTrigger__c
Custom Field :- Status__c
Custom Parent Object with Custom Field
It is parent custom object used for building a lookup relationship with childObjTrigger__c
Custom Child Object:- childObjTrigger__c
Custom Field:- Status__c
Custom Child Object with Custom Field
It is child custom object that is lookup relationship and associated with parentObjTrigger__c
You can download file directly from github by click here
Final Output → To get source code live demo..
Other related post that would you like to learn.
Step 1:- Apex Class Trigger : checkboxStatus.apxt
From Developer Console >> File >> New >> Apex Trigger
checkboxStatus.apxt [Apex Class Controller]
Other related post that would you like to learn To Find Some Important Additional Information
If you think you and your family members also like to earn money in additional time, then go this link. In this site, you can earn money for the lifetime at low effort. To Earn Unlimited Everyday With This Trick, Sign Up Free and Get Magic.. Get Started for Free
FAQ (Frequently Asked Questions)
What will happen if we perform update on after update trigger?
You can call this method in the trigger, but they will be executed after trigger ends, so no error will happen. For example, I used it to automatically fill some fields that require ID of record, that can’t be received in Before trigger.
What is difference between trigger new and trigger old?
The values in Trigger. old after the workflow update will NOT contain the “description” field that was updated in the workflow. The values in Trigger. new after the workflow update will contain any existing fields that were populated upon the object’s creation AND the “description” workflow updated field.
What is the difference between before trigger and after trigger?
Before triggers are used to update or validate record values before they’re saved to the database. After triggers are used to access field values that are set by the system (such as a record’s Id or LastModifiedDate field), and to effect changes in other records.
Final Output → To get source code live demo..
Hi, This is Vijay behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net
Originally published at https://www.w3web.net on August 5, 2020.