You need to sign in to do that
Don't have an account?
Project2
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
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
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.
Thanks.
I now get an error
"Save error: only aggregate expressions use field aliasing"
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];
It fixed the problem. Thanks,