You need to sign in to do that
Don't have an account?
How to Bulkify trigger in this scenario
Hello All,
I have requirement like when ever case is inserting, i have to insert Account, Contact and assign the inserted account and Contact to the case which is inserting. For this my approach is like below, But it wont work out because it is not getting Account id for inserting contact. How to achieve this?
I reuest anyone to give solution.
for (Case c : Trigger.New) // I am using before insert and Before Update
{
Account acc = New Account();
acc.Name = c.SuppliedName;
acc.Phone = c.SuppliedPhone;
CreateAccount.add(acc);
Contact con = New Contact();
con.LastName = c.SuppliedName;
con.AccountId = acc.Id;
con.Phone = c.SuppliedPhone;
con.Email = c.SuppliedEmail;
CreateContact.add(con);
c.AccountId = acc.Id;
c.ContactId = con.Id;
}
insert CreateAccount; //List of Account
insert CreateContact; //List of Contact
Thanks,
Uday
insert CreateAccount; //Account list
for(Integer i = 0; i < CreateAccount.Size(); i++) {
CreateContact[i].AccountId = CreateAccount[i].Id;
}
insert CreateContact; // List of Contacts