Home Uncategorized Salesforce.com Roll-up Summary Fields
Perhaps you’ve run into a limitation with the Salesforce.com Rollup Summary field functionality. While this is an incredibly useful function, roll up summary fields can only be used in very specific architectures.  You must come up with some other way to replace the functionality of a roll up summary field when you don’t have the prerequisite architecture or other needs of the system can’t permit that architecture. I’ll show you below how to get around the limitations.

You should use a rollup summary field when you have a set of child records to a parent record and you want to total some value from those child records.

Roll-up Summary Limitations

Here are a few of the limitations of a roll-up summary field (there are probably others):
– you must be in a master-detail relationship in order to use them
– the field being rolled up cannot be a formula field.
– you can only put 10 roll-up summary fields on an object

So what do you do when you can’t comply with one of the above?

Write a trigger!

A trigger can conveniently overcome all of the limitations identified above. (with the one complicating factor being that you can only write a trigger in Enterprise/Platform/Unlimited editions of Salesforce.com)

To replace the rollup summary functionality, put the trigger on the child object and have it fire whenever a record of that object type is saved. When the trigger is executed, it should collect the value that is to be totaled from the originating record, then go up to the parent object (which now does not need to be in a master-detail relationship), and collect that same value from every other child record. Do the math, then place the result in a custom field on the parent record.

An Example

So for example, imagine a company that uses a Unit custom object (kind of like Products) against their Opportunities to list what clients are buying. They have a Vendor Order record (custom object) also where they order those units from their vendor. The Unit object is child to the Vendor Order object also. So the Unit is the child in a master detail relationship to the Opportunity but in a lookup relationship to the Vendor Order. Unit can’t be in a master-detail relationship with Vendor Order because the Vendor Order record doesn’t exist when the Units are added to the Opportunity. In master detail relationship, parents must exist before children.

If the unit record contains a Price to the customer, that can be conveniently totaled on the Opportunity using a roll-up summary field. The unit will also have a Vendor Price to record what it costs to buy the unit from the vendor. But a rollup summary field isn’t available on the Vendor Order because it isn’t in a Master-Detail relationship. So the Vendor Order total price isn’t possible via rollup summary field.

By placing a trigger on the Unit object however, we can get our total. That trigger can execute each time the Unit record is saved, then take the Vendor Price from that Unit record, get the Vendor Price from every other Unit record associated with that Vendor Order, do the math, then save that value in the Vendor Order, Vendor Order Total Price field.

Get Help from Snapptraffic Consulting

Obviously, the challenge a typical salesforce.com customer faces is getting the trigger written. You’ll need a development environment and someone who knows how to write in APEX. If you don’t have those resources available to you. Feel free to contact us, we’d be glad to help. A trigger like the one noted about takes us about 3 hours to produce. (You can find our current rates on our website, noted below). Generally we can have it written within a day or two of your request.

You may also like

Leave a Comment