You need to sign in to do that
Don't have an account?
CMaine
Trigger to Fill Text Field on Parent Record with Text from Child record on Newest Child
Hello Everyone,
First time poster-- Use case is this:
I have an object called Goals__c with a set of child records underneath that are Goal_Measurement__c records. I want to add measures and for the latest recorded measure to roll-up to the Goal record. I've discovered I need to do a trigger to complete this but know very little about triggers. Does anyone have an example trigger like this I amy be able to redefine and fit?
Thanks for any help in advance
With Spring '09 this does not require a trigger and can be done through cross-object workflow and field Updates. See my thread here on how to get it active:
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=27960#M27960
All Answers
I think I have a solution, but this won't work for me every time. This should update my field on the parent called Number_Towards_Goal__c whenever a child record has the field Number_Measure__c greater. This is fine when our goals are positive, but sometimes we measure negatively and so we need to be able to measure just the latest record...
Any ideas?
for ( Goal_Measurement__c m : Trigger.new )
{
//for loop handler here
}
Goal__c g = [select id, Number_Towards_Goal__c from Goal__c where id = :m.GoalId];
List< Goal__c > aList = new List< Goal__c >();
List< Goal__c > aList = new List< Goal__c >();
for ( Goal_Measurement__c m : Trigger.new ) { Goal__c g = [select id, Number_Towards_Goal__c from Goal__c where id = :m.Goal__cId]; if ( m.Number_Measure__c > g.Number_Towards_Goal__c )
{
g.Number_Towards_Goal__c = m.Number_Measure__c;
gList.add( g );
} }
update gList;
With Spring '09 this does not require a trigger and can be done through cross-object workflow and field Updates. See my thread here on how to get it active:
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=27960#M27960