0

I have 2 custom objects sharing a master detail realtionship. Object A is the parent, Object B is the child. Object B has a lookup field to Account. I want to create a field on object A that will count the number of unique Object B records based on the account look up field on object A

e.g. If the following are object B records:

  • Acc A
  • Acc A
  • Acc A
  • Acc b

The total number of records should be 2 considering Acc A has been repeated. Any ideas?

1 Answer 1

1

There are a two basic options. You can either write your own rollup logic, which isn't tremendously complicated, but does require technical knowledge. Alternatively, you can use one of the popular free rollup tools out there like Declarative Lookup Rollup Summary or RollupHelper. I prefer the former but have no affiliation to either

If you write your own, you will use the SOQL Aggregate Function COUNT_DISTINCT(Field). I know DLRS has an equivalent, and would be mildly surprised if any other rollup tool out there is missing it.

2
  • So trying to use rollup summary here, Count selected & what should be selected in 'meeting criteria' field? 1) Can't see account field on object B for criteria. 2) Thinking to use cross object formula instead - can you assist with logic?
    – SF Admin
    Commented Oct 5, 2022 at 18:34
  • Out of the box rollup or one of the tools? That feature does not support any sort of unique count. You have to use an alternative listed above. If you are doing so, make sure you use whatever option reflects Count Distinct, not plain Count. As for the cross-object formula, the logic shouldn't be complicated. The formula editor has a field path selector.
    – Adrian Larson
    Commented Oct 5, 2022 at 19:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .