You need to sign in to do that
Don't have an account?

TRIGGER: update child records when parent record is updated
Hi All,
Please bear with me. I am an APEX newbie and needed some assistance please.
Goal: I wanted to update the checkbox (SentForApproval__c) in Child Object (Rate_sheet__c) to TRUE if the Parent Record (Lead) Status (Lead_Status_NEW__c) was set to "CA Completed". This is a lookup relationship.
Parent Object: Lead
Child Object: Rate_sheet__c
Here's what I have so far and I am unsure how to complete the code or even correct this:
Any help is greatly appreciated. Thank you
Please bear with me. I am an APEX newbie and needed some assistance please.
Goal: I wanted to update the checkbox (SentForApproval__c) in Child Object (Rate_sheet__c) to TRUE if the Parent Record (Lead) Status (Lead_Status_NEW__c) was set to "CA Completed". This is a lookup relationship.
Parent Object: Lead
Child Object: Rate_sheet__c
Here's what I have so far and I am unsure how to complete the code or even correct this:
trigger CAforApproval on Lead (after update){ set<Id> leadIds = new set<Id>(); map<Id, Lead> mapLead = new map<Id, Lead>(); list<Rate_sheet__c> listRateSheet = new list<Rate_sheet__c>(); for(Lead lead : trigger.new) { leadIds.add(lead.Id); mapLead.put(lead.Id, lead); } listRateSheet = [SELECT SentForApproval__c, Lead__r.Id FROM Rate_sheet__c WHERE Lead__r.Id IN : leadIds]; if(listRateSheet.size() > 0) { for(Rate_sheet__c rs : listRateSheet) {
Any help is greatly appreciated. Thank you
All Answers
Thanks for the help. However, it triggers regardless of what Lead Status I set. It should only trigger once I set the Lead_Status_NEW__c to "CA Completed".
Thanks in advance.
Please help me I have one custom object project and standard object opportunity,
I am creating the project fields in Opportunity while creating new opportunity.
Now, i want to update the project fields in opportunity when we make changes in project fields
Hi pcon,
The code is absolutely helpful but would like to know if I want to update only the new version of child records when the parent is updated. How would I compare the new version of child records and update only those.?
I have a scenario, So when ever an Account is updated, a new Contact is getting created under that Account. And I want the new Contacts to be updated not the contactswhich are already been craeted earlier under the same Account. I want new version of contacts to be updated.
Can you plz help me with this? Thanks in advance!