I have a Visualforce page which create a product record, a priceBookEntry record and a opportunityLineItem record.

I don't understand why in only one case, I get this error : enter image description here

In my code, I first create the product then the priceBookEntry and the opportunityLineItem.

If I try to create the OpportunityLineItem record between the opportunity and the pricebook as an other user, it works well, it just doesn't work with one user.

The currency of the opportunity is USD and the currency of the priceBookEntry is AED.

This is my code :

 this.theProductToInsert.IsActive = true;

        insert this.theProductToInsert;

        PriceBookEntry thePriceBookEntry = new PriceBookEntry(
            IsActive = true,
            Pricebook2Id = this.thePriceBook.Id,
            Product2Id = this.theProductToInsert.Id,
            UnitPrice = 1           

        insert thePriceBookEntry;

        System.debug('*** thePriceBookEntry: ' + thePriceBookEntry);

        insert new OpportunityLineItem(
            OpportunityId = this.theOpportunity.Id,
            PricebookEntryId = thePriceBookEntry.Id,
            Quantity = this.theOpportunityLineItem.Quantity,
            UnitPrice = this.theOpportunityLineItem.UnitPrice,
            Status__c = this.theOpportunityLineItem.Status__c,
            Lead_time__c = this.theOpportunityLineItem.Lead_time__c

How the currency of the priceBookEntry is selected please?

2 Answers 2


Try setting the CurrencyIsoCode on the PricebookEntry before insert.

thePricebookEntry.CurrencyIsoCode = this.theOpportunity.CurrencyIsoCode;

If you are fetching the PricebookEntry record from the existing records and you are getting this error i.e. pricebook entry currency code does not match opportunity currency code. Then try to add opportunityLineItem.PricebookEntryId = ExistingPricebookEntry.Id; instead of opportunityLineItem.PricebookEntry = ExistingPricebookEntry;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .