function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Benedict Yeo 6Benedict Yeo 6 

Clone Order Line Items into custom object

I've just started using Apex, and am trying to get the Line Items in Orders to reflect into a custom object Collection when a new Collection record is created. I've created another object called Collection Item as well.
However, I really can't get it to work.. Is there anyone who can point me in the correct direction? Thanks!
SonamSonam (Salesforce Developers) 
You need to create a trigger on OpportinityLineItem Object to clone the Line Item record and save it  in the Collection Item object.

Below code is a basic one to create a record in a custom object when a record in inserted in a standard object:


trigger statusUpdate on OpportinityLineItem (after insert)

{ List<Comms__c> commlist = new List<Comms__c>();

for(OpportinityLineItem a : trigger.new)
{ Comms__c comm = new Comms__c ();
comm.Name = 'testName';
commlist.add(comm); }
insert commlist;

}