+ Start a Discussion
Debendra Ray 8Debendra Ray 8 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, List has no rows for assignment to SObject: [] while inserting Quote

Hi All,
I'm getting the following error while inserting quote in a test class :
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, List has no rows for assignment to SObject: []
Please find the test class appended herewith :
@istest(SeeAllData=true)  private class TestSubmitforQuoteApproval {             static testmethod void test() {        Test.startTest();                   //Account acc = [select Id from Account limit 1];                   Opportunity oppr = new Opportunity();           //oppr.AccountId = acc.ID;           oppr.Annual_Contract_Value_ACV__c = 111;           oppr.BU__c = 'MJ';           oppr.CloseDate = Date.today();           oppr.Contract_Opportunity_Estimate_CoE__c = 111;           oppr.Total_Contract_Value_TCV__c = 111;            oppr.Name = 'SubmitforQuoteApproval';            oppr.StageName = 'Prospecting';             oppr.Date_on_Opportunity_Prospecting_Stage__c = Date.today();             //oppr.UpdatedForReminderToApprover__c = Date.today();           insert oppr;                      Quote quot = new Quote ();           quot.Name = 'TestPropForSandbox2016-1';            //quot.Status ='Draft';           quot.OpportunityId = oppr.id ;           insert quot;
}
}

Any help towards resolving this issue will be much appreciated

Thanks & Rgards,

Debendra Ray
Debendra Ray 8Debendra Ray 8
Hi All,
Further to the above email, I've a lookup field Account in the Quote Object - I believe , failure to assign the Account Lookup value to the Quote is resulting in the above error. However, please could someone show me how to assign the Account Lookup Value to the Quote Object in the Apex Test Class.

An early response on this will be much appreciated.

Thanks & Regards,

Debendra
Medhya MahajanMedhya Mahajan
Hi Debendra, 

There a 2 errors as i can make out from your question:
  •  FIELD_CUSTOM_VALIDATION_EXCEPTION : this is due to some Validation rule throwing error. You need to check the error in the Debug log to find which validtion rule is failing and create correct data accordingly.
 
  • List has no rows for assignment to SObject: this is because your query is returning no results.Instead of querying the Account, I suggest you create one as shown below.
@istest(SeeAllData=true)  
private class TestSubmitforQuoteApproval {             
static testmethod void test() 
{        

Test.startTest();                   

//Account acc = [select Id from Account limit 1];

Account acc = new Account (Name = 'test');
                   
Opportunity oppr = new Opportunity();           
//oppr.AccountId = acc.ID;           
oppr.Annual_Contract_Value_ACV__c = 111;           
oppr.BU__c = 'MJ';           
oppr.CloseDate = Date.today();           
oppr.Contract_Opportunity_Estimate_CoE__c = 111;          
oppr.Total_Contract_Value_TCV__c = 111;            
oppr.Name = 'SubmitforQuoteApproval';            
oppr.StageName = 'Prospecting';             
oppr.Date_on_Opportunity_Prospecting_Stage__c = Date.today();             
//oppr.UpdatedForReminderToApprover__c = Date.today();           
insert oppr;  
                    
Quote quot = new Quote ();           
quot.Name = 'TestPropForSandbox2016-1';            
//quot.Status ='Draft';           
quot.OpportunityId = oppr.id ;           
insert quot;

Let me know if it helps.

Regards
Medhya Mahajan