• Divya Krishnan 1
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi everyone, I'm having trouble with a test class. I'm passing a value to the target class variable but when the SOQL query executes, it returns "System.QueryException: List has no rows for assignment to SObject". Please help


Class
global class myClass{
public String AccountName{get;set;}
public Account accId{get;set;}
public String CNum{get;set;}

public VarsityAppInvoice(ApexPages.StandardController cAccount){         accId = (Account)cAccount.getRecord();         CNum = [Select Customer_Number__c FROM Account where id=:accId.id].Customer_Number__c;     }


   public Boolean getAccountStatus(){
     AccountName= [SELECT Name FROM Account WHERE Customer_Number__c=:CNum].Name;
     if(AccountName=null){
        return false;
     } else {
        return true
     }
   }

}

TestClass
@isTest
global class myClassTest{
static myClass con = new myClass();

public myClass(){
con.CNum='123456';
}

    @isTest static void testGetAccountStatus(){
            Boolean results = con.getAccountStatus();
            System.Debug(results);
     }

}

Even if I update con.CNum in the "testGetAccountStatus" method, I get the same error back, when the test runs. "System.QueryException: List has no rows for assignment to SObject"


 
  • March 28, 2015
  • Like
  • 0