Trigger - Create contact when new account created

 

Trigger - Create contact when new account created



Another Example:

Trigger Code: CreateAccountContact.apxt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
trigger CreateAccountContact on Account (after insert) {
     
    list<contact> contacts = new list<contact>();
     
    for(account acc : trigger.new){
         
        if(acc.Industry == 'Banking'){
             
            contact con = new contact();
             
            con.LastName = acc.name;
             
            con.Phone = acc.Phone;
             
            con.AccountId = acc.Id;
             
            contacts.add(con);
             
        }
         
    }
 
    insert contacts;
}

Comments

Popular posts from this blog

Trigger Scenario 8 : Preventing the users to create Duplicate Accounts