function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
srk goudsrk goud 

TRIGGER when account record is created corresponding contact should be created....what is id here?

trigger TriggerAccountContacts on Account (after insert) {
list<contact> cons=new list<contact>();
    for(account a:trigger.new){
        contact c=new contact();
        c.lastname=a.name;
        c.Phone=a.phone;
        c.Description=a.description;
        c.AccountId=a.id; //what is accountid here is it record id of account object
        cons.add(c);
    }
    insert cons;
}
Best Answer chosen by srk goud
Ankit BobdeAnkit Bobde
Hi Srikanth,

Account's record id is getting stored into contact's Accountid that means in accounts lookup in contact object in every iteration  of that for loop.
Every child will have an lookup field of its parent object which indeed can store its parent id in it.

Regards,
Ankit

All Answers

Azhar Aziz GAzhar Aziz G
Hey Srikanth - Yeah!. Account record Id will be store in accountId field. above Code  assigining ID correctly, no need to change.
srk goudsrk goud
Thank you...is every child has a field to store parent record id?
c.AccountId=a.id;// assigning account id to contact objects account id
Ankit BobdeAnkit Bobde
Hi Srikanth,

Account's record id is getting stored into contact's Accountid that means in accounts lookup in contact object in every iteration  of that for loop.
Every child will have an lookup field of its parent object which indeed can store its parent id in it.

Regards,
Ankit
This was selected as the best answer