function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
 
Kaaviya P 4Kaaviya P 4
I'm getting 1 error while test the class:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, error: []
Class.AccountProcessorTest.TestAccountProcessorTest: line 6, column 1

What is my  mistake I dont know,Anyone correct my mistake

public class AccountProcessorTest {
    public static testmethod void TestAccountProcessorTest(){
     Account a = new Account();
        a.Name = 'Test Account';
        Insert a;
        system.debug('account a :'+a.id);
        
        Contact cont = New Contact();
        cont.FirstName ='Ankit';
        cont.LastName ='Avula';
        cont.AccountId = a.Id;
        Insert cont;
        system.debug('contact cont :' +cont.id);
        
        List<Id> accIds = new List<Id>();
        accIds.add(a.Id);
        
        Test.startTest();
        AccountProcessor.countContacts(accIds);
        Test.stopTest();
        
        Account ACC = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];
        System.assertEquals(ACC.Number_of_Contacts__c, 1);
    }
VIPUL GALWADEVIPUL GALWADE
Disable the Validation Rule on Account Object and then try again it will do the trick