function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JaxBeachJaxBeach 

Workflow trigger from case created date based on not receiving an email?

Hi,

I need to send out time triggered email alerts on cases that haven't received an email response.  Does anyone know how I would code that - I would base it on createdDate but I don't know how to create a formula for email received equals zero.

thanks.
Best Answer chosen by JaxBeach
Venkat PolisettiVenkat Polisetti
Case does not have a field for Last Activity date time. The solution I have here would invove an Apex Trigger and a Work Flow rule.
  • Add a new custom field to Case object.
    • Name: Activity Count (Activity_Count__c)
    • Type:  Numeric
    • Length: 6
    • Scale: 0
    • Default value: 0
  • Create an Apex Trigger on the Task object that would update the above custom field on the Case object, whenever a new email is added to the activity
trigger UpdateCountOnCase on Task (after insert)
{
    Set<Id> caseIds = new Set<Id>();
    
    for (Task t : Trigger.New)
    {
        if (String.valueof(t.WhatId).StartsWith('500'))
            caseIds.add(t.whatId);
    }

    if (caseIds.size() > 0) {

        List<Case> caseList = [select id, Activity_Count__c from Case where Id in :caseIds];

        if (caseList.size() > 0) {

            for (Case c : caseList)
            {
                if (c.Activity_Count__c == null)
                    c.Activity_Count__c = 0;
                c.Activity_Count__c++;
            }

            update caseList;
        }
    }
}
  • Create a work flow rule on Case object that would fire whenever a case is created. 
    • Rule Criteria: Activity Count equals 0 
    • Add a time dependent trigger that would fire whenever you want (10 days from case opened date) and add an email alert. 
  • You are all set. When you create a new Case, it would schedule an email alert for a future date and if there is no activity within that time, it would send the alert. If you have received an email before that time, SF would automatically remove the scheduled alert from the system as your rule criterial is no longer true.

Let me know if this works.
Thanks,
Venkat

All Answers

Venkat PolisettiVenkat Polisetti
Case does not have a field for Last Activity date time. The solution I have here would invove an Apex Trigger and a Work Flow rule.
  • Add a new custom field to Case object.
    • Name: Activity Count (Activity_Count__c)
    • Type:  Numeric
    • Length: 6
    • Scale: 0
    • Default value: 0
  • Create an Apex Trigger on the Task object that would update the above custom field on the Case object, whenever a new email is added to the activity
trigger UpdateCountOnCase on Task (after insert)
{
    Set<Id> caseIds = new Set<Id>();
    
    for (Task t : Trigger.New)
    {
        if (String.valueof(t.WhatId).StartsWith('500'))
            caseIds.add(t.whatId);
    }

    if (caseIds.size() > 0) {

        List<Case> caseList = [select id, Activity_Count__c from Case where Id in :caseIds];

        if (caseList.size() > 0) {

            for (Case c : caseList)
            {
                if (c.Activity_Count__c == null)
                    c.Activity_Count__c = 0;
                c.Activity_Count__c++;
            }

            update caseList;
        }
    }
}
  • Create a work flow rule on Case object that would fire whenever a case is created. 
    • Rule Criteria: Activity Count equals 0 
    • Add a time dependent trigger that would fire whenever you want (10 days from case opened date) and add an email alert. 
  • You are all set. When you create a new Case, it would schedule an email alert for a future date and if there is no activity within that time, it would send the alert. If you have received an email before that time, SF would automatically remove the scheduled alert from the system as your rule criterial is no longer true.

Let me know if this works.
Thanks,
Venkat
This was selected as the best answer
JaxBeachJaxBeach
Thanks so much for your help with this :-)