Skip to content

Instantly share code, notes, and snippets.

@TheShubhamVsnv
Created June 30, 2021 12:47
Show Gist options
  • Save TheShubhamVsnv/60656db8b5c83d68e459c653fd2802f4 to your computer and use it in GitHub Desktop.
Save TheShubhamVsnv/60656db8b5c83d68e459c653fd2802f4 to your computer and use it in GitHub Desktop.
<!-- wp:paragraph --> <p>When an Account is updated and the Website is filled in, update all the Profile field on all Contacts to:</p> <!-- /wp:paragraph --> <!-- wp:list --> <ul><li>Profile = Website + ‘/’ + First Letter of First Name + Last Name</li></ul> <!-- /wp:list -->
trigger TriggerExample3 on Account (After Update)
{
if(Trigger.isAfter && Trigger.isUpdate)
{
Set<Id> AccountId_Set = new Set<Id>();
new list<contact>();
for(Account ac : trigger.new)
{
if(ac.website != null)
{
AccountId_Set.add(ac.id);
}
}
if(AccountId_Set.size()>0)
{
List<Contact> Contact_List = [select Id,Firstname,Lastname,Profile__c,Accountid,Account.website from contact where Accountid in :AccountId_Set];
for(Contact con : Contact_List)
{
if(con.FirstName != Null)
{
con.Profile__c = con.account.website + '/' + con.FirstName.substring(0, 1) + con.lastname;
}
}
update Contact_List;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment