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
AndyPandyAndyPandy 

Trigger To Add Together Multiple Roll-up Summary Fields

Hi All,

 

I posted a question in the General board a while back, asking how to add together multiple roll-up summary fields, using standard functionality, Link = http://boards.developerforce.com/t5/General-Development/Add-Together-Multiple-Roll-Up-Summary-Fields/m-p/491781#M74789

 

However, after no response, I checked with SFDC Support, who said the only available method was to use an APEX Trigger.

 

Being completely new to APEX, I have come here to ask if someone could provide some help/tips on where to go to learn how to do this specific task.

 

I have the SObject "Account" in the Org I admin, as well as two new Custom Objects called "Business Plan" and "Capital Pipeline".

 

Each User in my Org is the owner of multiple Accounts, and each Account has multiple "Capital Pipeline" deals.

 

I have created a number of Roll-Up Summary fields on the Account SObject, which roll-up the sum of the "Capital Pipeline" deal values.

 

I now need to roll-up the Account roll-ups for each User in the Org, so I get an overall sum of "Capital Pipeline" deal values for all the Accounts owned by each User.

 

Is this something which is possible via a Trigger?

 

For example:

 

User A owns Account 1, Account 2 and Account 3.

 

Account 1 has two Capital Pipeline deals, worth a total of £125,000

Account 2 has four Capital Pipeline deals, worth a total of £275,000

Account 3 has three Capital Pipeline deals, worth a total of £100,000

 

Each Account would have their own Roll-Up Summary field showing the totals as above.

 

I need my Business Plan record for User A, to show a "Total Deal Value" of £500,000 (the total of all the "Capital Pipeline" deals related to the Accounts they own).

 

Each user would have their own Business Plan record, and when they accessed it, the "Total Deal Value" would have to be correct for them.

 

Any help would be HUGELY appreciated.

 

Thanks,

 

Andy

sfdcfoxsfdcfox

So, you have a Business Plan custom object that stores the totals per user, correct?

 

I don't know why you wouldn't just use a custom report for this (e.g. a custom link to a report that filters to "my accounts"), but if you wanted to do this in a trigger, you'd probably want two triggers:

 

1) The first trigger, on accounts, just queries for all Business Plans for owners involved in the trigger, and calls an update function on those records.

 

2) The second trigger, on business plans, queries the sum of all accounts for the account by user.

 

However, since you're using rollups, this may be complicated by that fact (rollups do not calculate until after triggers execute), so you'd have to instead have the first function call a @future method, and that future method could call the update on business plans (the rollups would then be correct, and the second trigger would calculate correctly).

 

You might need to engage a consultant for a few hours if you need it to be fully written for you; you need someone that can have a dialog with you, and write the code for you, including the test classes you'll need as well. If you have the time to learn Apex Code, however, then it certainly is within the realm of possibility.