+ Start a Discussion
sfg1sfg1 

Error Message System.QueryException: List has no rows for assignment to SObject in Messaging.InboundEmailHandle test class

I am getting error "Error MessageSystem.QueryException: List has no rows for assignment to SObject" in Test class.
Please guide me in this.

@ISTest
public class Email_TEST {
  public static testmethod void testmethod1() {
         Location2__c lc= new Location2__c();
         lc.Workout_Status__c= 'Past Due 1 Backlog';
         lc.Workout_Status_Updated__c= 'test';
         insert LC;
        Task t = new Task();
        t.Subject = 'Fax Packet Successful';
        t.Description = 'testdata';
        t.Status = 'Completed';
        t.Priority = 'Low';
        t.WhatId = lc.Id;
        lc.Fax_Failed__c = False;
        lc.Fax_Verified__c = True;
        insert t;
        Messaging.InboundEmail email = new Messaging.InboundEmail() ;
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

        email.subject = 'Test' ;
        email.fromname = 'Test Test';
        env.fromAddress = 'Test@email.com';
        email.plainTextBody = 'Test';
        
        EpiEmailBlast emailProcess = new EpiEmailBlast();
        emailProcess.handleInboundEmail(email,env);
        System.debug('Email is: ' + Email);
        System.debug('Env is: ' + Env);
}
}

        
     
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi sfg1,
  • The exception is because of you are not getting any record in your SOQL query.which meet the where criteria so it gives an error.

Please mark as best answer if the information is informative.

Thanks
Rahul