We need an error whenever a case is closed but there are remaining open tasks not completed. Is there any easy way of doing this? Also, is it possible to update a date field in the CASE based on the date a specific activity is closed?
Attribution to: Tami
Possible Suggestion/Solution #1
I agree with @Monith Kumar. I think you'll need a trigger. You could do something where you count the number of non closed Tasks for Cases that are being saved with their IsClosed changing from false to true. Just keep in mind that triggers need to be written to handle bulk updates, so you have to assume that more than one Case is being updated in the Trigger. Here's a rough idea to get you started.
trigger CaseTrigger on Case (after update) {
// Find all cases that are being closed...
Set<Id> newlyClosedCaseIds = new Set<Id>();
for (Id caseId : Trigger.newMap.keySet()) {
if (Trigger.newMap.get(caseId).IsClosed &&
!Trigger.oldMap.get(caseId).IsClosed) {
newlyClosedCaseIds.add(caseId);
}
}
// For every newly closed Case that has at least one
// not closed task add an error to the Trigger.newMap entry.
// Adding the error to the Trigger.new entry will prevent the save
// and add the error message to the page messages that get displayed on
// the page.
for (AggregateResult aggResult : [
Select Count(Id), WhatId
From Task
Where WhatId In :newlyClosedCaseIds
And IsClosed = false
Group by WhatId
Having Count(Id) > 0
]) {
Id caseId = (Id) aggResult.get('WhatId');
Case errorCase = Trigger.newMap.get(caseId);
// change error message as appropriate...
errorCase.addError('Cannot close case since there are non closed tasks: ' +
errorCase.SuppliedName);
}
}
Attribution to: Peter Knolle
Possible Suggestion/Solution #2
To answer second part of your question; "Also, is it possible to update a date field in the CASE based on the date a specific activity is closed?" , you can create a Cross Object Workflow to do that.
- Create a Workflow Rule on the "activity" object.
- Associate a field update with this workflow rule to update whichever date field (or any other) you want to update on Case object.
Attribution to: Rahul
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5454