Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
I think you will have to go for a trigger .Looks like no shortcut or out of box stuff – Mohith Shrivastava Dec 14 '12 at 19:10

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) {

    // 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 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: ' +
share|improve this answer

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.

  1. Create a Workflow Rule on the "activity" object.
  2. Associate a field update with this workflow rule to update whichever date field (or any other) you want to update on Case object.
share|improve this answer
+1. Theoretically cross object workflows could be used to increment some hidden counter up & down as tasks are opened & closed (it would fail when you delete a Task though). – eyescream Dec 17 '12 at 21:55
@eyescream - you can click the little up-arrow thingie rather than putting '+1' in a comment :-) – metadaddy Dec 17 '12 at 22:54
I blame my annoying wifi. Thx @metadaddy – eyescream Dec 17 '12 at 23:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.