Hi ,
Good day!
I'm facing an error when I'm running a test class.
Error:- 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]
Stack Trace:-Class.test_EntitlementUtil.test_EntitlementUtil: line 46, column 1
Code:-
@isTest(seealldata=true)
public class test_EntitlementUtil{
static testMethod void test_EntitlementUtil (){
test.startTest();
Account a = new Account(Name = 'Test Opp',Email_Domain__c = 'samarth.com',Website='www.cb.com',BillingStreet = 'Test Street',BillingState='Assam',BillingCountry = 'India',CurrencyISOCode = 'USD');
insert a;
Pricebook2 pb = [select Id from Pricebook2 where IsStandard = true limit 1];
Product2 p = new Product2(Name = 'CBSVC', isActive = true);
insert p;
PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = p.Id, UnitPrice = 1, isActive = true);
insert pbe;
//create a new opp
Opportunity o = new Opportunity(Name = 'Test Opp',
AccountId = a.id,
CloseDate = date.today(),
StageName = '1 - Closed Won',
Win_Summary__c = 'test',
LeadSource='Community',
//Use_Case1__c = 'Profile Management',
// Customer_Support_Contact_Email__c = 'sudhirn@sudhir.com',
PriceBook2Id = pb.Id,
Close_Reason__c = 'test'
//Loss_Summary__c = 'test'
);
insert o;
Opportunitylineitem qli = new Opportunitylineitem(
opportunityid = o.id,
PriceBookEntryId = pbe.Id,
Quantity = 1,
UnitPrice = 500,
Discount_Percent__c = 29,
Subscription_Terms__c = 1,
Number_of_Nodes__c = 10,
NS_Start_Date__c = Date.Today() - 10,
NS_End_Date__c = Date.Today()
);
insert qli;
entitlement e = new entitlement(name = 'sudhirent',
Opportunity__c = o.id,
accountid=a.id,
StartDate = date.today() - 10,
EndDate = date.today() );
insert e;
list<entitlement> ent = [select Opportunity__c,StartDate,EndDate from Entitlement where Opportunity__c = :o.id];
for( entitlement gent : ent )
{
gent.StartDate = o.NS_Start_Date_Min__c;
gent.EndDate = o.NS_End_Date_Max__c;
update gent;
}
//EntitlementUtil myTC = new EntitlementUtil();
Test.stopTest();
}
}
Please help me.
Thanks in advance...
Regards,
Srinivas
You may check similar discussions:
https://salesforce.stackexchange.com/questions/110751/error-pricebookentryid-pricebook-entry-is-in-a-different-pricebook-than-the-onhttps://salesforce.stackexchange.com/questions/81314/pricebook-entry-is-in-a-different-pricebook-than-the-one-assigned-to-the-opportuhttps://developer.salesforce.com/forums/?id=906F000000090d7IAAhttps://salesforce.stackexchange.com/questions/142974/price-book-entry-is-in-a-different-pricebook-than-the-one-assigned-to-the-opport