2
 Map<Id, Integer> mapActivityHistoryCountToCase = new Map<Id, Integer>();

           for( Case caseObj : [SELECT count(SELECT ID FROM ActivityHistories)  countActivity
                        FROM case where Id in : caseIds])
           {
               mapActivityHistoryCountToCase.put(caseObj.Id, caseObj.countActivity);
           }

I am not able to use Count for the activity history. please suggest .

I tried it this way too. But of no use.

  Map<Id, Integer> mapActivityHistoryCountToCase = new Map<Id, Integer>( 
                     [SELECT count(SELECT ID FROM ActivityHistories) 
                        FROM case where Id in : caseIds);

1 Answer 1

1

ActivityHistories is a list so it knows its own length already. Try this:

Map<Id, Integer> mapActivityHistoryCountToCase = new Map<Id, Integer>();

for( Case caseObj : [SELECT (SELECT Id FROM ActivityHistories) 
                     FROM Case WHERE Id IN :caseIds])
{
  mapActivityHistoryCountToCase.put(caseObj.Id, caseObj.ActivityHistories.size());
}

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.