You need to sign in to do that
Don't have an account?
nagarjuna guraja
Need Trigger for Execution
Hello,
Write a trigger such that we have two objects Account and Contact. Field named numberofcontacts on Account. If we insert number of contacts as 3, then three contacts should be created.
Best Regards
Write a trigger such that we have two objects Account and Contact. Field named numberofcontacts on Account. If we insert number of contacts as 3, then three contacts should be created.
Best Regards
Can you please try this one.
trigger numberofcontactsonAcc on Account (after insert) {
list<Contact> lstcon = new list<Contact>();
for(Account acc : trigger.new){
if(acc.Create_N_Contacts__c != null){
for(Integer i = 0; i < acc.Create_N_Contacts__c; i++){
contact con = new contact();
con.LastName = acc.Name + i;
con.AccountId = acc.Id;
lstcon.add(con);
}
}
}
if(!lstcon.isEmpty()){
insert lstcon;
}
}
If it helps,Pls, mark it as best answer.
Thank you.
You can also refer this discussion -> https://developer.salesforce.com/forums/?id=906F00000008p4WIAQ
Thank you .