You need to sign in to do that
Don't have an account?
Ashok0572
Getting error in Test class plx help me
DeleteQuoteLineItemCTLRTest.myUnitTest -- System.DmlException: Insert failed. First exception on row 0;
first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Quote Account and the Opportunity Account must be insync: [Account__c]
Stack trace: Class.DeleteQuoteLineItemCTLRTest.myUnitTest: line 58, column 1
==========================================================
@isTest
private class DeleteQuoteLineItemCTLRTest {
static testMethod void myUnitTest() {
Organization__c organizationObj = (Organization__c)TestDataHelper.createSObject('Organization__c');
insert organizationObj;
TestDataHelper.createSalesRegionUser(organizationObj.id);
Account accObj = (Account) TestDataHelper.createSObject('Account');
accObj.BillingCountry = 'Germany';
insert accObj;
AccountContactRole accountContactRole=(AccountContactRole)TestDataHelper.createSObject('AccountContactRole',true,1);
Opportunity oppty=(Opportunity)TestDataHelper.createSObject('Opportunity');
oppty.accountId=AccountContactRole.AccountId;
accountContactRole.IsPrimary=true;
insert accountContactRole;
insert oppty;
system.assertequals(oppty.accountid,accountContactRole.AccountId);
Quote quote = (Quote)TestDataHelper.createSObject('Quote');
quote.opportunityId=oppty.id;
quote.Sold_To__c = accobj.Id;
//quote.Account__c= accObj.Id;
//quote.Account__c = accObj.Id;
insert quote;
system.assertequals(quote.OpportunityId,oppty.id);
list<QuoteFieldIds__c> quoteFields=TestDataHelper.getQuoteFieldIds();
insert quoteFields;
system.Test.setCurrentPage(Page.AppendSaveURLQLI);
Test.startTest();
// Run as System Administrator
//system.runAs(systemAdministrator){
//runDeleteQuoteCTLR(quote);
ApexPages.currentPage().getParameters().put('newid',quote.id);
ApexPages.currentPage().getParameters().put('oppid',oppty.id);
runDeleteQuoteCTLR(quote);
system.assertequals(ApexPages.currentPage().getParameters().get('newid'),quote.id);
system.assertequals(ApexPages.currentPage().getParameters().get('oppid'),oppty.id);
//ApexPages.currentPage().getParameters().put('save_new','Https://login.salesforce.com?id=test');
//runDeleteQuoteCTLR(quote);
//}
Test.stopTest();
}
static void runDeleteQuoteCTLR(Quote quote){
ApexPages.Standardcontroller controller=new ApexPages.Standardcontroller(quote);
DeleteQuoteLineItemCTLR deleteQLICTLR=new DeleteQuoteLineItemCTLR(controller);
deleteQLICTLR.deleteQLI();
deleteQLICTLR.appendSaveURL();
}
}
first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Quote Account and the Opportunity Account must be insync: [Account__c]
Stack trace: Class.DeleteQuoteLineItemCTLRTest.myUnitTest: line 58, column 1
==========================================================
@isTest
private class DeleteQuoteLineItemCTLRTest {
static testMethod void myUnitTest() {
Organization__c organizationObj = (Organization__c)TestDataHelper.createSObject('Organization__c');
insert organizationObj;
TestDataHelper.createSalesRegionUser(organizationObj.id);
Account accObj = (Account) TestDataHelper.createSObject('Account');
accObj.BillingCountry = 'Germany';
insert accObj;
AccountContactRole accountContactRole=(AccountContactRole)TestDataHelper.createSObject('AccountContactRole',true,1);
Opportunity oppty=(Opportunity)TestDataHelper.createSObject('Opportunity');
oppty.accountId=AccountContactRole.AccountId;
accountContactRole.IsPrimary=true;
insert accountContactRole;
insert oppty;
system.assertequals(oppty.accountid,accountContactRole.AccountId);
Quote quote = (Quote)TestDataHelper.createSObject('Quote');
quote.opportunityId=oppty.id;
quote.Sold_To__c = accobj.Id;
//quote.Account__c= accObj.Id;
//quote.Account__c = accObj.Id;
insert quote;
system.assertequals(quote.OpportunityId,oppty.id);
list<QuoteFieldIds__c> quoteFields=TestDataHelper.getQuoteFieldIds();
insert quoteFields;
system.Test.setCurrentPage(Page.AppendSaveURLQLI);
Test.startTest();
// Run as System Administrator
//system.runAs(systemAdministrator){
//runDeleteQuoteCTLR(quote);
ApexPages.currentPage().getParameters().put('newid',quote.id);
ApexPages.currentPage().getParameters().put('oppid',oppty.id);
runDeleteQuoteCTLR(quote);
system.assertequals(ApexPages.currentPage().getParameters().get('newid'),quote.id);
system.assertequals(ApexPages.currentPage().getParameters().get('oppid'),oppty.id);
//ApexPages.currentPage().getParameters().put('save_new','Https://login.salesforce.com?id=test');
//runDeleteQuoteCTLR(quote);
//}
Test.stopTest();
}
static void runDeleteQuoteCTLR(Quote quote){
ApexPages.Standardcontroller controller=new ApexPages.Standardcontroller(quote);
DeleteQuoteLineItemCTLR deleteQLICTLR=new DeleteQuoteLineItemCTLR(controller);
deleteQLICTLR.deleteQLI();
deleteQLICTLR.appendSaveURL();
}
}
Please try with below code .Your error is saying that the Opportunity and Quote should tag to same account .
Please let me know it helps or you need any help .
Please try below code.
Let us know if it helps.
Thanks for posting,
and i'm getting the error after copying urs code
Variable does not exist: quote.Id at line 26 column 31
Thanks for posting,
i'm getting the error after copying urs code
Invalid field accountId for SObject Quote at line 24 column 9
By removing
quote.Account__c = AccountContactRole.AccountId;
getting Null pointer exception
Please remove below line and test ,let me know any issue .
quote.accountId=AccountContactRole.AccountId;
by removing mentioned code,
getting an error
System.NullPointerException: Attempt to de-reference a null object