You need to sign in to do that
Don't have an account?
Melissa Carey
Need help writing a trigger!
We have a field on the Account level called "Monthly Fee". I'd like to create a new field on the parent level so we can see a roll-up summary of the children accounts. Please help me with writing the trigger!
If this is a Rollup-Summary Field and the relationship is Master-Detail, than you don't need to do a Trigger to do simple Roll Ups.
If the relationship is Master-Detail, you can handle this when you create the Field.
Create the field on Account as a type Rollup-Summary and tell it what you want to child field you want to summarize.
The relationship is not Master-Detail. I was told I need to use a trigger.
I'm not completely 100% sure of what you're looking for, but if you have a parent-child relationship, you can use __r. So let's say you have a Parent__c and a Child__c custom object. On the parent you want to fill the Report__c field, and you want to call the Summary__c field from the child.
So you have something like: Parent__c.Report__c = Parent__c.Child__r.Summary__c
So, crudely written:
trigger DoThis on Parent__c(before update)
{
for(Parent__c p: trigger.new)
{
p.Report__c = p.Child__r.Summary__c;
}
}
It might not be exact but it's a start.