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
BrandiTBrandiT 

Roll Up Summary Challenge

I have a custom object called Headings that has a many to many relationship to Opportunities.  I've created the junction object Opportunity Headings to show this relationship.  Opportunity Headings also has a lookup relationship to Account.  Headings looks up to another custom object called Category.  I know it's confusing, so I'm including a picture to explain the relationships  :)

 

graph

 

I need a roll up summary field on Category (in blue above) that will count the number of Opportunity Headings (in red) with unique Accounts (in green).

 

I know how to do the roll-up summary field to count Opportunity Headings, but I can't figure out how to only count one per account.  So ABC account could have 10, opportunity headings, but I only one to show that there in one account in that category.

 

I would love to hear any ideas you can come up with for this problem!!

 

Thanks!!

                                                          

Surfwriter.comSurfwriter.com

Hi Brandi,

 

You could update a field in category with an apex trigger on inserts or updates to Opp heading.

BrandiTBrandiT

Have you done anything similar to this where you could share the code?

 

I've done a few triggers with roll-up summaries, but never one where I'm looking for a count of distinct values.  I tried so many ways of writing this trigger and can't seem to figure it out.