How to create same orderItem(some field are modified) when I create any OrderItem record related to order using trigger?

  • 1
    Hello Ravi, Welcome SFSE, What you have tried so far? can you paste the code here? – rahul gawale Dec 6 '18 at 8:53
  • Yes, please, show as what it is that you have tried so far.... – Carlos Naranjo Dec 6 '18 at 9:07

This can be achieved by a simple trigger on OrderItem Object on event afterInsert of like below:-

Clone method will give you a duplicate OrderItem record : Reference

trigger OrderItemTrigger on OrderItem (after insert) {

        List<OrderItem> orderItemsToInsert = new List<OrderItem>();
        for(OrderItem record: Trigger.new){
            OrderItem newOrderItem = record.clone(false, true, false, false);
         //   newOrderItem.field =''; //make changes on fields you want

            orderItemsToInsert.add(newOrderItem  );
        Database.insert(orderItemsToInsert );


Also, add the recursive check code in your Org, because you do not want to keep on adding new order Items recursively.

public Class checkRecursive{

    private static boolean run = true;

    public static boolean runOnce(){

     return true;  
        return run;

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.