You need to sign in to do that
Don't have an account?
VSK98
Hello All,
I have to update the contact records when the account checkbox is false...Above code will work for the same?
Regards,
VSK98
Update child records
Trigger Updatechildrec on Account (after update ) List <Account > lst = new list<account>() If (trigger. Isafter&&trigger.Isupdate){ For(account a: trigger.new) If(a.id!=null && a. Check box == false) lst. Add(a) } For(contact c: [Select I'd, accountid,checkbox from contact where accountid =:lst]){ C. Checkbox = false Update c // we can list also to update... }
Hello All,
I have to update the contact records when the account checkbox is false...Above code will work for the same?
Regards,
VSK98
List <Id>lst = new list<Id>();
You can do this by using a Process Builder. And you can also write an Apex Trigger for the same. (See the Apex Trigger code below.)
trigger updateChildRecords on Account (After Insert,After update) {
if(trigger.isAfter && ( trigger.isUpdate || trigger.isInsert) ){
list<account> accList=(trigger.isInsert || trigger.isUpdate)?trigger.new:trigger.old;
set<string> accountIdSet=new set<string>();
for(account ac:accList){
if(ac.checkbox__c==false)
accountIdSet.add(ac.Id);
}
list<contact> conList=new list<contact>();
for(contact con:[select id,accountId from contact where accountId in:accountIdSet]){
con.checkBox__c=false;
conList.add(con);
}
if(conList.size()>0)
dataBase.update(conList);
}
}
If this will fulfill your requirement, please mark this question as solved.
Thanks,
Duke_Sfdc