+ Start a Discussion
Project2Project2 

ERROR: SOQL without querying the requested field

 

I get an error when i execute the below code.
object Dispute_New__c and Document_ID__c are related (lookup)

trigger UpdateCaseStausonDoc on Dispute_New__c (after update) {
  List<Document_ID__c> openlineitems =
  [SELECT j.id FROM Document_ID__c j 
  WHERE j.Dispute_Case_Rela__r.id IN:Trigger.new
  FOR UPDATE];
  for (Document_ID__c li:openlineitems){
 /** Update field Reference_Key2__c  in all cases except null value of
  /** picklist Dispute_Case_Rela__r.status__c 
  if(li.Dispute_Case_Rela__r.Status__c !=''){
  li.Reference_Key2__c = li.Dispute_Case_Rela__r.status__c;
  }
 
}
Thanks for your help

 

Best Answer chosen by Admin (Salesforce Developers) 
MiddhaMiddha

you dont need "j" as alias, just remove that from query and try again:

 

[SELECT id,Dispute_Case_Rela__r.status__c FROM Document_ID__c WHERE Dispute_Case_Rela__r.id IN:Trigger.new FOR UPDATE];

All Answers

MiddhaMiddha

You are trying to access a field value which you have not queried. Change your query to add this field i.e. SELECT j.id, j.Dispute_Case_Rela__r.Status__c FROM Document_ID__c

 

It should work.

Project2Project2

Thanks. 

 

I now get an error

"Save error: only aggregate expressions use field aliasing"

MiddhaMiddha

you dont need "j" as alias, just remove that from query and try again:

 

[SELECT id,Dispute_Case_Rela__r.status__c FROM Document_ID__c WHERE Dispute_Case_Rela__r.id IN:Trigger.new FOR UPDATE];

This was selected as the best answer
Project2Project2

It fixed the problem. Thanks,