You need to sign in to do that
Don't have an account?
Ankita Gupta 65
Bulkify code in apex trigger
I have the following scenario-
I have 2 objects with master-detail relationship. Object A-Detail and object B-Master
On the trigger on Object A(before insert), I'd like to create a B record and add it to the A record. For instance-
trigger appendChild on A(before insert)
{
for(A aRecord : trigger.new)
{
B bRecord=new B(Name='xyz');
insert bRecord;
aRecord .field=bRecord.Id;
}
}
How can I bulkify this code to avoid DML insert inside for loop?
I have 2 objects with master-detail relationship. Object A-Detail and object B-Master
On the trigger on Object A(before insert), I'd like to create a B record and add it to the A record. For instance-
trigger appendChild on A(before insert)
{
for(A aRecord : trigger.new)
{
B bRecord=new B(Name='xyz');
insert bRecord;
aRecord .field=bRecord.Id;
}
}
How can I bulkify this code to avoid DML insert inside for loop?
Hi Ankita,
Hope you are doing great !!!
I would like to inform you that, In Master Detail Relationship, when you will try to create child record, then it will ask to fill relationship field related to parent. In short, Relationship field on child object is mandatory, without it you can not create child record (Detail record).
Thanks
Let us know if it helps.