Is there a way to return count(open activities) on case when I build a SOQL query in workbench ?


SELECT Id, {count(open activities)} FROM Case WHERE AND Status = 'open' AND {open activities != null}



Count() can only be used in root queries, it cannot be used in nested or inner query. Hence, this is how you can achieve -

integer openActivitiesCount = 0;
List<Case> csList = [SELECT Id, (SELECT Id FROM OpenActivities) FROM Case Where Status =: 'New'];
for (Case cs : csList){
    openActivitiesCount = openActivitiesCount + cs.OpenActivities.size();

You should be querying the Task or Event object with WhatId as Case like below

SELECT count(id) FROM Task WHERE WhatId =: caseId AND IsClosed = False

SELECT count(id) FROM Event WHERE WhatId =: caseId AND IsClosed = False 

Hope it helps.

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.