-
-
Save TheShubhamVsnv/6d6ccb4787f6cc5e1ab18be57b0ed8d6 to your computer and use it in GitHub Desktop.
Create Account record whenever contact is created without an 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 ContactCustomTriggerExample on Contact (after insert) { | |
List<Account> accListToInsert = new List<Account>(); | |
for(Contact con : Trigger.New) { | |
//check if account is null on contact | |
if(con.AccountId == null ) { | |
Account acc = new Account(); | |
//Add all required field on Account | |
acc.Name = con.LastName; | |
acc.Phone = con.Phone; | |
accListToInsert.add(acc); | |
} | |
} | |
if(!accListToInsert.isEmpty()){ | |
insert accListToInsert; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment