You need to sign in to do that
Don't have an account?
tmbarry
Update Multiple Child records from a Parent Record
I am trying to update a field on a child record - Participation_Level_Tiers__c.Total_Regist__c from a field on the Parent record Account.Total_Registrants__c
trigger UpdatePricing on Account (after insert, after update) { ////////////////////////////////////// // Created 07/18/2013 by Todd Barry /////////////////////////////////// for( Account parent: Trigger.new) { List<Participation_Level_Tiers__c> children = [ SELECT Total_Regist__c from Participation_Level_Tiers__c where Account__c = :parent.Id]; List<Account> currentacct = [Select Total_Registrants__c from Account Where account.id = :parent.Id]; List<Participation_Level_Tiers__c> childrenToUpdate = new List<Participation_Level_Tiers__c>(); For (Participation_Level_Tiers__c thischild: children ) { thischild.Total_Regist__c = currentacct[0].Total_Registrants__c; childrentoupdate.add(thischild); } IF(childrenToUpdate != null) { update childrentoupdate; } }}
The trigger saves fine, but when I update the Account record nothing happens?
Any thoughts?
Also, how would I use a debug statement and where would i put it to see the Account.Total_Registrants__c value being pulled?
Well the code is not optimized, I made few changes, but still the code is not bulk safe but should work
From the code it looks like you could either use formula field on the child object ?
If no, then you can maybe try this: (I did not test this code, but it should work)
and for debug statements, use system.debug(logginglevel.error,'Account TotalReg value:'+parent.Total_Registrants__c); and look for debuglogs under setup