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
test vijaytest vijay 

SObject row was retrieved via SOQL without querying the requested field + apex

hello Developers,
I am facing Below error while I execute my batch class through test class.
 SObject row was retrieved via SOQL without querying the requested field: Contract.SBQQ_Quote_r
can anybody help me to resolving this.
Thanks in advance
 
Best Answer chosen by test vijay
ravi soniravi soni
Hello Vijay,
this is common error and solutin is very easy.
I think you are passing soql query through test class. In that query you are missing some fields that is using into batch class.
for example if you are trying to use Contract.Name,Contract.SBQQ_Quote_r but you are not passing SBQQ_Quote_r field via query then you can face  this error.

let's have an another example for understanding.
List<Account> accList = [SELECT Id, Name FROM Account WHERE Name like ='%test'];
for(Account acc : accList){
System.debug('Account industry is'+ acc.Industry);
}
the solution of above example is that 
List<Account> accList = [SELECT Id, Name,Industry FROM Account WHERE Name like ='%test'];

let me know if it helps you and marking it as best answer.
Thank you