-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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