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

Trigger to update child with parent values

I have this trigger which will update a child record with values from the parent.


For some reason I'm getting a "variable does not exist : trigger" error at the line which I underlined : 


trigger ChildTriggerToUpdateChildWithParentValues on Grandchild__c (before insert) {

   // Get a list of all Parent Ids
   Set<Id> parentIds = new Set<Id>();
    for (child__c chld : {

   // Get a map of all Parents with Grandparent field information
Map<Id, Parent__c> parentsById = new Map<Id, Parent__c>();
parentsById.putAll([SELECT Id, MyField2__c FROM Parent__c WHERE Id IN :parentIds]);

 for(child__c chld :{ 



Any idea what is causing this ? 


Thank you.


Hi Zoom,

Your trigger is on the 'Grandchild__c' object and you are trying to loop round a list of 'Child__c' from the new list.