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
Rick MacGuiganRick MacGuigan 

Determine if an account has any related records

I need to remove accounts that have no related list records (i.e. contact, custom object records,..) What  is the easiest way to flag an account record with a field that calcualtes to a '1' or '0' (has records / does not have records?) 

I do have rollup helper but would prefer to use a formula field if possible. 
ManojjenaManojjena
Hi Rick,

I think you can create a child_count one field in Account and write trigger in all child object to update the same  field .
Write a batch class to check the child count an dif the child count is zero then delete teh account .

However you need to decide the time when you need to execute the batch .

Thanks 
Manoj
K_McRaeK_McRae
Rick,

Create rollup fields on the parent record that count the number of child records of each type.

You'll be able to report against them and work out what IDs need to be removed.

cheers,
Keith
Rick MacGuiganRick MacGuigan
Keith, thanks for the response. I can't see the contact records from an account to rollup. Any suggestions ?
K_McRaeK_McRae
Ah, yes... my idea only works for master-detail relationships.

You could consider A Declarative Rollup Summary Tool for Force.com Lookup Relationships (https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000009O5p).

I have not used it myself, yet, but seems very popular.
Rick MacGuiganRick MacGuigan
Ill see if the rollup helper people can do this. We have their product.
Rick MacGuiganRick MacGuigan
Rollup Helper does the trick.