3

I am trying to pull list of cases in workbench that has open activities and my query is :

SELECT Id, (SELECT Subject, Status, Priority, OwnerId FROM OpenActivities) FROM case

The above query pulls all the cases irrespective of they have openactivities or not. Can someone please guide me how to add a where clause here.

Thanks

2

Use Inner SOQL for same would be as below

SELECT Id, (SELECT Subject, Status, Priority, OwnerId FROM OpenActivities) FROM case where Id IN (Select WhatId from OpenActivity)

But kindly note Inner SOQL is not supported and hence you cant do this without further using if clause in apex

 list<Case> lst=[ SELECT Id, (SELECT Subject, Status, Priority, OwnerId FROM OpenActivities) FROM case];

 list<Case> lstcasewithopenActivities=new  list<Case>();
 for(Case c:lst){
    if(c.OpenActivities.size()>0){
       lstcasewithopenActivities.add(c);
    }
 }

Another approach is to write some code to keep the count on Case record when an activity is created or edited

Some sample code already written in below blog if that helps you

http://rjpalombo.com/2013/11/counting-open-activities-salesforce/

|improve this answer|||||
  • Hi Mohith, Thanks for your reply. So just to confirm, there is no way to filter cases in workbench that have no open activities, right ? – sf_user Jul 19 '15 at 21:01
  • 1
    Atlesst not I am aware of – Mohith Shrivastava Jul 19 '15 at 21:15

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.