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
btran3btran3 

Trigger for parent accounts

Hello all,

 

I want to create a trigger(after update) for a child to parent account relationship.  I have a custom field at the account level that sums up the total revenue for every account based off of their opportunity products.  I would like to be able to sum up that total revenue field for all child accounts and put that amount at the parent level account.  Could someone help me write this trigger?  Thank you!

Madhan Raja MMadhan Raja M

You don't need to create a trigger for this scenario. You can use Roll-Up Summary field to achieve this:

 

Roll-Up Summary: A read-only field that displays the sum, minimum, or maximum value of a field in a related list or the record count of all records listed in a related list.

 

Follow the below steps:

 

1. Create a custom Roll-Up Summary field called 'Revenue from Product' in Opportunity object which sum up the revenue field from Opportunity Product object.

 

2. Create a custom Roll-Up Summary field called ' Total Revenue' in Account object which sum up the 'Revenue from Product' field from Opportunity object.

 

Let me know if you have any queries.

 

Madhan Raja M

btran3btran3

That will not work because the field is not a master detailed field so you can't run a roll up summary off of it.  I also forgot to mention the field at the child account level sums up any products that have payments every month.

Madhan Raja MMadhan Raja M

If you are using standard Account -> Opportunity -> Opportunity Product objects, then by default you can use Roll-Up Summary field.

 

Can you brief and give some example for:- the field at the child account level sums up any products that have payments every month.

 

Madhan Raja M

btran3btran3

Here is an example of what I mean:

We have products that are charged either one time, annually or MONTHLY.  The field I have in the opportunity level is a custom field that sums up all of the products in each opportunity that is charge monthly.  Since the field is a custom field and not a master detailed field I can not use the Roll-Up Summary field.