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
VIGNESH BALASUBRAMANIANVIGNESH BALASUBRAMANIAN 

Cannot create Opportunity line item on update call

Hi Everyone,

I want to create Opportunity line item when I update Opportunity Stage to "Closed Won".

It works for when create new Opportunity but not works when I update an existing Opportunity.

It shows below error
FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity)
Thanks,
Vignesh
Lokeswara ReddyLokeswara Reddy
Hi Vignesh,

The product which you are trying to add under Opportunity line item is not part of the associated Pricebook. 
Make sure there is an entry, under the pricebook, for the product you are tyring to create Opty line item.

Regards
Lokesh
VIGNESH BALASUBRAMANIANVIGNESH BALASUBRAMANIAN
I got this problem because trigger fires recursively.I add recursive class to avoid this.Now it works fine
public class stoprecurssion{
public static boolean flag=true;
public static boolean runonce(){
if(flag){
   flag=false;
  }
else {
   return flag;
  }
   return true;
 }
}
Thanks