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
MrTheTylerMrTheTyler 

For a report, how do I distinguish records with children from those without children

I have 2 objects on which I want to report: Cases and Surveys.  Cases are master objects of surveys.   I've created a "Report Type" (Setup>Create>Report Types) which shows all cases with surveys fields even if there is no related survey (ie. a left outer join).

 

How can I segment my cases into 2 groups: cases with surveys and cases without surveys?

 

 

Cheers,

 

 

Tyler 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Assuming that the relationship is indeed Master-Detail and not just a Lookup, you can use a Rollup Summary Field on the Case object to sum all surveys. You can then use that number directly in a report (i.e. group by Survey Count), or you can create a formula field (Has Surveys (Text) = IF(SurveyCount__c>0,"Yes","No").

All Answers

sfdcfoxsfdcfox

Assuming that the relationship is indeed Master-Detail and not just a Lookup, you can use a Rollup Summary Field on the Case object to sum all surveys. You can then use that number directly in a report (i.e. group by Survey Count), or you can create a formula field (Has Surveys (Text) = IF(SurveyCount__c>0,"Yes","No").

This was selected as the best answer
MrTheTylerMrTheTyler

Thank you!  For future reference, how might one accomplish this if it is a lookup relationship as opposed to a master/detail?

sfdcfoxsfdcfox

For that, you'd have to do your own Rollup Summary trigger. I don't have an example offhand, but basically you'd run a after event trigger (after insert, update, delete, undelete), gather the ID values of all involved records, and run an update on the "parent" records. Then, you'd have a second trigger, on (after update, after undelete) that counts the children for that record.