You need to sign in to do that
Don't have an account?

Trigger for updating field in child records
I have three objects: General_Intakes__c, Contact, and Households__c
The Households__c is the Parent of Contact. the Contact has a lookup field called Household_Id_del__c to the Household.
The General_Intakes__c is the child of both Households and Contacts, with lookup fields called Primary_Contact__c and Primary_Household_Id__c.
I was trying to write a trigger, which I am fairly new at, that when the Household_Id_del field is changed in the Contact object, the Primary_Household_Id__c field on the General_Intakes__c is updated to reflect the same.
Essentially, Primary_Household_Id__c must be the same as Primary_Contact__r.Household_Id_del__c.
I tried copying some code I found in these boards, but I keep getting this error:
Error: Compile Error: Didn't understand relationship 'Households__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 42
Here is the code:
trigger GeneralIntakeHHId on Contact (after update) { for( Contact parent: Trigger.new) { List<General_Intakes__c> children = [ SELECT Primary_Household_ID__c from General_Intakes__c where Primary_Contact__r.id = :parent.Id]; list <Households__c> household = [Select Household.Id from Households__c where Household.id = :parent.Household_ID_del__c]; List<General_Intakes__c> childrenToUpdate = new List<General_Intakes__c>(); for(General_Intakes__c thischild: children ) { if( thischild.Primary_Household_Id__c != household[0].Id) { thischild.Primary_Household_Id__c = household[0].Id; childrenToUpdate.add(thischild); } } if( !childrenToUpdate.isEmpty()) { update childrenToUpdate; } } }
The error is for list <Households__c> household = [Select Household.Id
Any help would be much appreciated.
I found coding that worked:
All Answers
The problem is that you named your object as Households__c so now you have to use Householdss__c
I found coding that worked: