+ Start a Discussion
Mary Ardelyn NabongMary Ardelyn Nabong 

Cloning is not populating my custom fields

Hi guro,

I have a custom object(Billing Plan) with a custom field (opportunitylineitem, text). Everytime I clone the Billing Plan opportunitylineitem is not populated. I build the relationshop One(pooportunity line item)  to Many (Billing Plan).
1. build a trigger to create a billing plan as soon as opportunily line item is added.
2. another trigger to update the opportunity line item with Billing ID.
3. when i clone Billing Plan, everything is populated except the opportunity line item ID(text) , not required, not unique.

Below is the code for my Billing plan
------------------------------------------------------------------------
trigger BillingSchedule on Schedule__c (after insert) {
 
    for(Schedule__c BSupd:trigger.new){
        system.debug('BSupd: '+ BSupd.Opportunity_Line_Item__c);
     Id lineitemid = BSupd.Opportunity_Line_Item__c;
        if (lineitemid != null){
        Opportunitylineitem oplnitm =[select id from opportunitylineitem
                                      where id=:lineitemid limit 1];
       oplnitm.Schedule__c = BSupd.Id;
        update oplnitm;
     }
   }
}

------------------------------------------------------
Thanks in advance.
Mary
James LoghryJames Loghry
Is the billing plan the same as Schedule__c here?  Also, this trigger happens to cover #2 in your scenario above, but where's the logic for #1? When you post the code for #1, please use the code format button (< >) too, so we can easily copy and update it for your help.

Lastly, have you considered implementing this with a Process and a Flow in place of a trigger?