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
padmini sspadmini ss 

FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (must have the same currency as the order): [PricebookEntryId]

Hi This is my Test class its working fine Sandbox 93% coverage, but while moving to production 
i am getting this error 
FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (must have the same currency as the order): [PricebookEntryId] 
@isTest(seeAllData=TRUE)
    private class testSalesOrderReportGenerator {
    static testMethod void testSalesOrderReportGenerator() {
        List<OrderItem > lstoplitm= new list<OrderItem>();

  Account a = new Account(name ='testac1',BillingCity='BillingAddress',BillingCountry='India',BillingStreet='test BillingStreet',BillingPostalCode='12345',BillingState='Haryana');
        insert a;
        
        
        
Product2 prod = new Product2(Name = 'Laptop X200',Family = 'Hardware');
insert prod;

Id pricebookId = Test.getStandardPricebookId();//This is available irrespective of the state of SeeAllData.

PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = pricebookId, Product2Id = prod.Id,UnitPrice = 10000, IsActive = true);
insert standardPrice;
 
PriceBook2 pb2Standard = [select Id from Pricebook2 where isStandard=true];


PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE Pricebook2Id = :pb2Standard.Id AND isActive=true LIMIT 1 ];


 Order o = new Order(name='test opp1',Status= 'Draft' ,  AccountId=a.id,CurrencyIsoCode= 'USD',EffectiveDate = Date.today(),Pricebook2Id = pb2Standard.Id);
       insert o;
    
 OrderItem op=new OrderItem (PriceBookEntryId=pbe.Id,quantity=1,Orderid=o.id,UnitPrice=pbe.UnitPrice );
      //insert op;
     lstoplitm.add(op);
     
     
     
      insert lstoplitm;
only in after this my business logic works, please kindly help me .

thanks
 
Best Answer chosen by padmini ss
Anoop yadavAnoop yadav
Hi,
Make a query on PricebookEntry and Oder to fetch the CurrencyIsoCode
and put the debug to check that both are same.
If not same then set the same for both.

All Answers

Anoop yadavAnoop yadav
Hi,
make a try by removing
CurrencyIsoCode= 'USD'
from Order.
padmini sspadmini ss

Removed 
CurrencyIsoCode= 'USD'
from Order., but still same error in only production @anoop

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (must have the same currency as the order): [PricebookEntryId] 
Stack Trace: Class.testSalesOrderReportGenerator.testSalesOrderReportGenerator: line 34, column 1,
pls help me out..

Anoop yadavAnoop yadav
Hi,
Make a query on PricebookEntry and Oder to fetch the CurrencyIsoCode
and put the debug to check that both are same.
If not same then set the same for both.
This was selected as the best answer
padmini sspadmini ss
Anoop pls tell me how to achive this to debug(writing query on
PricebookEntry & in  Oder), i am in  tension ...need to be moved to prodction urgently ..kindly help me..!!
Anoop yadavAnoop yadav
Hi,
Why you are using the below Line?
PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE Pricebook2Id = :pb2Standard.Id AND isActive=true LIMIT 1 ];
Use the below one instead.
PricebookEntry pbe = [ SELECT Id,Product2Id,Pricebook2Id,UnitPrice FROM PricebookEntry WHERE Id = :standardPrice.Id];



 
padmini sspadmini ss
hi Anoop , i simple paseed CurrencyIsoCode of PricebookEntry to Order, and its deployed successfully thank u so much Anoop.
Anoop yadavAnoop yadav
great..