There are 2 objects Account & Address and their relationship is master detail.

In address there is a checkbox called primary and most of the accounts will have 1 address which is marked as primary.

I want to know the accounts which don't have a primary address at all. For example there are 2 accounts A & B. Account A has 5 addresses and none of them have primary checked and Account B has 5 address in which 1 is primary and the other 4 non primary.

So when I run a report saying primary=false i am getting both accounts A (5 records for each non primary address) & B (4 records for each non primary address) instead of only account A. This is because B has 4 addresses which are not primary and report is pulling them.

Is there any different way or query where I can get only account with no primary address which means by our example only account A should come out but not account B?

  • Can put picture of your report condition – Santanu Boral Jul 6 '16 at 20:31

One solution is to create a roll up summary field on Account, filtering by the Primary field. You can then run reports where Primary Addresses equals 0.

For small databases, the following SOQL would also work:

Select Id From Account Where Id Not In
    (Select Account__c From Address__c Where Primary__c = True)

This would return all accounts that have no primary address. However, this query will fail for databases with hundreds of thousands of addresses.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.