You need to sign in to do that
Don't have an account?
Shweta Garg
Price book entry is in a different pricebook than the one assigned to the opportunity
Hi
I am facing the issue while deploying the test class in production. The test class is working fine in sandbox but failing in production
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity): [PricebookEntryId]
Here is my code
I have also checked the values in debug in production, the value of opportunity pricebookid and pricebookentry pricebookid are the same(system.debug('op.pricebook2Id!!!!'+op.pricebook2Id+'pbEntry.Pricebook2Id !!!'+pbEntry.Pricebook2Id);)
Please help me on this issue.
I am facing the issue while deploying the test class in production. The test class is working fine in sandbox but failing in production
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity): [PricebookEntryId]
Here is my code
@isTest public class CopytoOppLineItemTest{ @isTest static void testTrigger(){ Id pricebookId = Test.getStandardPricebookId(); //Pricebook2 pb = [select name,id from Pricebook2 where IsStandard =true LIMIT 1]; system.debug('pricebookId !!'+pricebookId ); Product2 prod = new Product2( Name = 'Product X', ProductCode = 'Pro-X', isActive = true ); insert prod; //Create your pricebook entry PricebookEntry pbEntry = new PricebookEntry( Pricebook2Id = pricebookId , Product2Id = prod.Id, UnitPrice = 100.00, IsActive = true ); insert pbEntry; Opportunity op = new Opportunity(); op.name = 'test'; op.closedate = Date.today(); op.StageName = 'Init'; op.pricebook2Id = pricebookId ; insert op; system.debug('op.pricebook2Id!!!!'+op.pricebook2Id+'pbEntry.Pricebook2Id !!!'+pbEntry.Pricebook2Id); OpportunityLineItem ol = new OpportunityLineItem(); ol.opportunityid = op.id; ol.quantity = 4; ol.TotalPrice = ol.quantity * pbEntry.UnitPrice ; ol.PricebookEntryId = pbEntry.id ; insert ol; } }
I have also checked the values in debug in production, the value of opportunity pricebookid and pricebookentry pricebookid are the same(system.debug('op.pricebook2Id!!!!'+op.pricebook2Id+'pbEntry.Pricebook2Id !!!'+pbEntry.Pricebook2Id);)
Please help me on this issue.
When I tried to google search your error I found below links with some solutions see if any of this will help you.
http://salesforce.stackexchange.com/questions/49426/pricebookentry-is-not-correctly-assigned
http://salesforce.stackexchange.com/questions/34863/test-code-for-the-new-standard-order-object
http://salesforce.stackexchange.com/questions/71816/error-in-test-class-as-field-integrity-exception
https://developer.salesforce.com/forums/?id=906F000000090d7IAA
http://salesforce.stackexchange.com/questions/81314/pricebook-entry-is-in-a-different-pricebook-than-the-one-assigned-to-the-opportu
http://salesforce.stackexchange.com/questions/49426/pricebookentry-is-not-correctly-assigned
Hope this helps you!
If this helps you mark it as solved.
Thanks and Regards
Sandhya
Hi Shweta,
Did you find a solution to this specific issue?
Kind Regards,
Swarna.
Yes that issue is resolved now.there was a process builder that was causing issue.
T