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
Bryan Revelant 7Bryan Revelant 7 

Apex Trigger on Parent update child

I have the below trigger, to update a child if a field on the parent is a specific value. 

I am getting the below error

Error: Compile Error: Invalid field Status__c for SObject ADR__c at line 28 column 1


trigger ADRParentUpdateChild on ADR__c ( after update, after insert) {

List<ADR__c > ParentRecords= [Select id, Next_Step__c, (Select ADR__c, Status__c FROM ADRUser__r) from ADR__c  WHERE id IN :Trigger.newMap.keySet()];

for(ADR__c parent: ParentRecords){
if(parent.Next_Step__c == 'Submit'){
   
parent.Status__c = 'Submit';
   }
   }
   
}
RedmossSubC4iRedmossSubC4i
It's not recognizing the API field name of Status__c.  It sounds like the field may not exist for that object  in the environment you're working in.  e.g. sandbox vs production.  Perhaps the API name is spelled incorrectly or you're working in a sandbox where that field is missing.  Or you tried to deploy a change set and forget to include that field.
Bryan Revelant 7Bryan Revelant 7
Status is on the child object. Not the parent. In my SOQL you can see that the field in on the child object ADRUser__r not ADR Object.
RedmossSubC4iRedmossSubC4i
I see. On the child object, have you confirmed that the custom field Status__c exists on that object in the environment that you're developing on?
RedmossSubC4iRedmossSubC4i
Apologies, just realized that the SOQL inner-relationship is the issue.
Bryan Revelant 7Bryan Revelant 7
Do have happen to know the issue with it?
RedmossSubC4iRedmossSubC4i
This should help: http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm

Might be since you didn't reference the plural name of the child object when referencing inside your SOQL.
New_DeveloperNew_Developer
You have loop the child too. try this
List<ADRUser__c> adruser = new List<ADRUser__c>();
for(ADR__c parent: ParentRecords){
if(parent.Next_Step__c == 'Submit'){
for( ADRUser__c adr : ParentRecords.ADRUser__r)
{  
adr.Status__c = 'Submit';
adruser.add(adr)
}
}
}
if(adruser.size()>0)
update adruser;