You need to sign in to do that
Don't have an account?
activityhistory and check to see if any record is there, if not, dont allow change of status on case
All,
I am trying to query for activity history and not allow change of status if there is no record for it.
Since activity history is special type, i could not use activityhistory in map since it cannot be queried so had to use
case. however, my code is not working it allows to change status despite there being no activityhistory.
what needs to be changed below?
thanks
trigger Checkcaseactivity on Case (before update) {
public Set<Id> setCaseId = new Set<Id>();
public Map<Id,case> mapActivityHisstory=new Map<Id,case>();
for(Case c: Trigger.New){
if(c.Status !=null && c.Status=='New' && c.Status != trigger.OldMap.get(c.Id).Status){
setCaseId.add(c.Id);
}
}
if(setCaseId.ISEMPTY()) return;
For(case ct: [SELECT (SELECT ActivityDate, Description,id,activitytype from ActivityHistories) FROM case
WHERE Id IN : setCaseId]){
mapActivityHisstory.put(ct.Id,ct);
}
for(Case c: Trigger.New){
if(mapActivityHisstory.get(c.Id) ==null){
c.addError('No Activity');
}
}
}
This Code May Help You..
If this is the solution please mark as solution. Thanks
All Answers
mapactivityhistory..get(c.id) won't return null, because there is obviously a case in the map. Instead, you need to check this:
Strictly speaking, activityhistories shouldn't be null, but may be depending on the API version you choose (older versions tend to return a null list, while newer API versions appear to always return a valid object that may simply be empty).
Error: Compile Error: Method does not exist or incorrect signature: [LIST<ActivityHistory>].isempty() at line 18 column 48
This Code May Help You..
If this is the solution please mark as solution. Thanks
If you want to implement same on event also , just replace case to event...
thanks
if(mapActivityHisstory.get(c.id).ActivityHistories.size() == 0) solved the issue and code worked.
Thanks to Shiv Shankar