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
CMaineCMaine 

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

Message Edited by CMaine on 03-23-2009 11:35 AM
Best Answer chosen by Admin (Salesforce Developers) 
CMaineCMaine

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

CMaineCMaine

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;

 

Message Edited by CMaine on 03-23-2009 11:35 AM
Message Edited by CMaine on 03-23-2009 11:36 AM
CMaineCMaine
I am really stuck on this and can't figure this out, anyone have any suggestions on where I can start?
CMaineCMaine

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

 

This was selected as the best answer