+ Start a Discussion
GMASJGMASJ 

Copy Opportuitylines to Orderlines

Hi, 

 Need help in resolving below error happening when adding opportuntiy products Please suggest me what is the issue here. 

Apex trigger SAASTRICS.OpportunityLineTrigger caused an unexpected exception, contact your administrator: SAASTRICS.OpportunityLineTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []: Class.SAASTRICS.OpportunityLineItemTriggerUtil.OrderLineCreation: line 37, column 1 
  
 
Trigger OpportunityLineTrigger on OpportunityLineItem (Before Insert, Before Update, After Insert, After Update){

  if(Trigger.isBefore) {
      OpportunityLineItemTriggerUtil.OrderLineCreation(Trigger.new);  
   }  

}


helper class
=========
public class OpportunityLineItemTriggerUtil{

  public static void OrderLineCreation(List<OpportunityLineItem> newLst){
     list<OrderItem> lstOrdItm = new list<OrderItem>();
     OrderItem ObjOrdItm = new OrderItem();
     
     for(OpportunityLineItem oppLn : newLst){ 
         ObjOrdItm.OrderId = oppLn.opportunity.SAASTRICS__Order__c;
         ObjOrdItm.PricebookEntryId = oppLn.PricebookEntryId;
         ObjOrdItm.Quantity = OppLn.Quantity;
         ObjOrdItm.UnitPrice = OppLn.UnitPrice;

lstOrdItm.add(ObjOrdItm);         
      }
      
       if(!lstOrdItm.isEmpty()){
          insert lstOrdItm;
        }
  
  }
  
}
Thanks
GMASJ