I am very new to CPQ, and I am given a test class to write directly. When I try creating order in my test class, I am getting this error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Opportunity must have a primary quote in order to create an order.: []
in test class - testSetup.
My test data factory:
public with sharing class TestDataFactory {
public TestDataFactory() {
}
public static Account getTestAccount(){
Account acc = new Account();
acc.Name = 'Test Account';
acc.Account_Cancel_Date__c = system.today();
acc.Account_Category__c = 'Regional';
return acc;
}
public static contact getTestContact(Account acc){
contact cont = new contact();
cont.lastname = 'Test Contact';
//acc.LastName = 'Testtt';
cont.Account = acc;
return cont;
}
public static product2 getProduct(){
product2 prods = new Product2(Name = 'Test Product 1', Line_of_Business__c = 'Dealer Inspire');
return prods;
}
public static Pricing_Table__c getPricingTable(id prodId){
Pricing_Table__c prt = new Pricing_Table__c(DI_Product__c = prodId, Billing_Type__c = 'Advance', DI_OEM__c = 'GM', Hinge_Day__c = 5, Legacy_PricebookEntryID__c = 'GMDigADUS', Dealer_Price__c = 123, DI_Brand_Name__c = 'Test', Docusign_Required__c = 'Yes', Wholesale__c = 321, InvoiceGroup__c = 'Acura_DigAd', Payment_Terms__c = '15', DIPricingMethod__c = 'Dealer Price');
return prt;
}
public static SBQQ__Quote__c getTestQuote( id accId){
SBQQ__Quote__c quo = new SBQQ__Quote__c();
quo.SBQQ__Account__c = accId;
quo.SBQQ__BillingCity__c = 'Hyderabad';
quo.SBQQ__BillingCountry__c = 'India';
quo.SBQQ__Key__c = '1233';
quo.ApprovalStatus__c = 'Approved';
quo.SBQQ__Ordered__c = false;
quo.Legacy_Quote_Id__c = '0065b00000rFb18AAC';
return quo;
}
public static Quote_Line_Migration__c getQuoteLineMigration(id quoteId){
Quote_Line_Migration__c qli = new Quote_Line_Migration__c();
qli.Quote__c = quoteId;
qli.is_Processed__c = true;
qli.Activated__c = true;
qli.Legacy_Quote__c = '0065b00000rFb18AAC';
qli.Legacy_Product__c = 'GMDigADUS';
return qli;
}
public static Opportunity getOpportunity(id quoteId, id AccId){
Opportunity o = new Opportunity(Name = 'TestOpp1', StageName = 'Demo', Type = 'Existing Business', AccountId =AccId, LeadSource = 'DI Chat',
CloseDate = Date.today(), Desired_Product_Services__c = 'Dealer Inspire',SBQQ__PrimaryQuote__c = quoteId);
return o;
}
public static order getOrder(id quoteId, id oppId){
Order ord = new Order();
ord.Name = 'Test order';
ord.status = 'Activated';
ord.SBQQ__Quote__c = quoteId;
ord.OpportunityId = oppId;
//ord.QuoteId = quoteId;
return ord;
}
public static Quote_Migration__c getQuoteMigration(){
Quote_Migration__c qm = new Quote_Migration__c();
qm.Legacy_Quote_Id__c = '0065b00000rFb18AAC';
return qm;
}
}
My testsetup in test class is:
@testSetup
static void createRecords() {
Account acc = TestDataFactory.getTestAccount();
insert acc;
Contact cont = TestDataFactory.getTestContact(acc);
insert cont;
SBQQ__Quote__c quo = TestDataFactory.getTestQuote(acc.Id);
quo.SBQQ__Ordered__c = true;
insert quo;
system.debug(quo.Id);
Quote_Line_Migration__c qlm = TestDataFactory.getQuoteLineMigration(quo.Id);
qlm.contracted__c = false;
insert qlm;
opportunity opp = TestDataFactory.getOpportunity(quo.Id, acc.Id);
insert opp;
order ord = TestDataFactory.getOrder(quo.Id, opp.Id);
insert ord; // Error: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Opportunity must have a primary quote in order to create an order.: []
}
During insert ord
, I am getting the error System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Opportunity must have a primary quote in order to create an order.: []
. Can I please get some help on how to rectify this error as I am new to CPQ