Skip to content

Instantly share code, notes, and snippets.

@TheShubhamVsnv
Last active June 18, 2021 19:52
Show Gist options
  • Save TheShubhamVsnv/31b0ff6a9583956ce39ff6112178510a to your computer and use it in GitHub Desktop.
Save TheShubhamVsnv/31b0ff6a9583956ce39ff6112178510a to your computer and use it in GitHub Desktop.
Salesforce Apex Trigger to check a check-box on account Object whenever a new contact created of a specific account
trigger AcconuntForContact on Contact (after insert , before update){
if(trigger.isInsert && trigger.isAfter){
set<id> ids = new set<id>();
for(contact con: trigger.new){
if(con.accountid!=null){
ids.add(con.accountid);
}
}
list<account> acclist = [select id,name,Contact_Created__c from account where id in: ids];
for(contact con : trigger.new){
for(account acc: acclist){
if(acc.id==con.accountid){
acc.Contact_Created__c= true;
}
}
}
if(accList.size()>0){
update acclist;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment