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
splashgordonsplashgordon 

Multiple masters

I have a need to rollup data from one custom object (timesheet) to multiple master objects. I already have a Master-Detail with one custom object (Delivery Project) but need to achieve the same rollup summary information to other custom objects (e.g. Resources, Timesheet Header etc.). I know that this is not possible through the main application front end as you can only have one Master-Detail relationship but it should be possibe using S-Controls or Apex code. Has anyone had experience of doing this and can point me in the right direction? This is my first post so please be gentle! Regards, Gordon Anderson
caroline_sfdccaroline_sfdc
Hi Gordon,

Welcome to the boards!

There's actually recipe entitled "Creating a Roll-Up Summary Field with an S-Control" in the Force.com Cookbook on page 157 -- I suggest you download that book and take a look! It's available free to all ADN members at http://wiki.apexdevnet.com/index.php/Members:Cookbook.

Hope that helps,

Caroline Roth
Co-Author, "The Force.com Platform Cookbook"
splashgordonsplashgordon
Hi Caroline and thanks to the link to the cookbook. That is really helpful. One thing I didn't appreciate (assuming I am reading it correctly) is that if I use S-Controls to get the data I need, I cannot then use that data in reports and formulas etc. Is there any way of coding a formula (in Java) that puts the result in a field that can then be used in reports etc. I am not keen to venture into Apex code as that will require us to purchase the Power Option for our Enterprise Edition which I will not be able to justify to our CFO. Any thoughts? Regards, Gordon.
caroline_sfdccaroline_sfdc
Hi Gordon,

What you mention about s-controls is true -- they are pieces of code that live on a page layout or in a button and only execute when a user accesses them through the UI. Logic inside the s-control will not run if a report or API call is accessing a record directly, so any data that is calculated by the s-control is only current as of the last time that a user viewed the record on a page layout.

Using an Apex trigger circumvents this issue because it is tightly coupled with the Force.com platform framework -- any time a record is updated, a trigger can execute logic and update field values so that data will always be up-to-date and can be used reliably in reports and formulas.

If you can't use Apex and you really need the rollup data for reports and formulas, one workaround might be to write a client application in the language of your choice that uses the Force.com API to calculate the values you need. The client app could then update one or more fields with those values directly, which would then make that field available for formulas and reports.

To ensure that the field values were up-to-date, you could either schedule that client app to run nightly/hourly/etc, or you could also try using a workflow rule w/ an outbound message to "wake up" the client app whenever an event happens in Salesforce that might change the value of the rollup.

This is a very heavy-handed approach, though, and is indicative of why having a server-side language like Apex is such a boon to the Force.com platform.

I'm sorry I don't have a better solution for your current problem -- if you or anyone else has a more elegant workaround, I'd love to hear about it too!

Caroline
splashgordonsplashgordon
Hi Caroline and thanks for the reply. You have confirmed my fears that Apex is the sensible way to go but is not, I think, an option for us. I am going to investigate using our internal developer resources to write a client side app. We definitely need the data to be available in reports etc. so S-Controls will not be sufficient. Thanks again for your help - it has been very useful.
splashgordonsplashgordon

Caroline,

I wonder if I could ask for your insight on this message again... I think I may now be able to go the Apex code route and am therefore reevaluating how I might achieve this requirement.  How easy/difficult it is will have a bearing on whether we go with Apex.

So, not wanting to get into too much detail, if I wanted to have a field on an object that effectively did a "RollUp Summary" on records in a related object and put the result in that field do you have a view what woud be involved in doing this in Apex code?  The two objects are related in a standard lookup (as opposed to a Master Detail) and it is not an option to relate them in a Master-Detail (and therefore use standard Roll-up summary functionality) as the "child" object is already in a Master-Detail relationship.

Any advice very much welcomed!

Thanks in advance,

Gordon.