Skip to main content
Hi, I'm trying to create 2 object records in apex. I'm having issues in bukifying the code. I have a Map<A,B> where A is master object and B is child object. Once I insert A, I need to update the field in B with record ID of A. Can anyone tell me how can this code be bulkified.
2 个回答
  1. 2017年5月2日 14:07

    trigger UpdateAccountid on Contact (after insert) {

    UpdteAccountIdOnContact.updateTitle(trigger.new);

    }

    public class UpdteAccountIdOnContact {

    public static void updateTitle(list<contact> lstContats){

    list<contact> lstOFCons = new list<contact>();

    for(contact c : lstContats){

    if(c.accountid != null){

    contact cc = new contact();

    cc.id = c.id;

    cc.Title = c.accountid;

    lstOFCons.add(cc);

    }

    }

    if(lstOFCons != null){

    update lstOFCons;

    }

    }

    }

    Please check once above code and let me know.

    Thanks

    Varaprasad