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
Brooks Johnson 6Brooks Johnson 6 

Query for Contacts Without Tasks

Hi Friends,

I have a requirement to find all contacts with no related tasks or if they do have a task to filter out certain types.  When I start with a base SOQL Query on the workbench I get an error that Task is not supported from Semi Join inner select.  The base query is:  

SELECT Id, Name FROM Contact WHERE Id NOT IN (SELECT WhoID FROM Task). Is there another way to do this? 
SandhyaSandhya (Salesforce Developers) 


You can try generating report from Accounts and contacts as below

Just use a Contacts & Accounts report where theLast Activity is blank

Best Regards,

Alain CabonAlain Cabon

There is no pure "declarative" solution (rollup summary field) or with a simple SOQL request for your problem.

That is a problem that you can "solve" with only a report as stated above but it is an incomplete solution (Activity is a task, an event or a calendar).

The only common solution is an Apex trigger (on insert, upate if conditions, and delete, +1/-1 on a counter) because even a standard rollup summary field is not possible here. The declarative processes and flows cannot manage the deletions.

The workaround to the standard rollup summary is a declarative rollup summary that is in fact a generator of trigger. 

A Declarative Rollup Summary Tool for Lookup Relationships
It is one of the only free tool of high quality but you need some work for the installation and the creation of your first declarative rollup summary.

This basic need has even a commercial package: