I want to escalate case if no one gives a reply(only in form of Email) for the case within 24hours.

I searched a little bit and figured a way I don't know if it's proper or not or if is there any other way to do this, as I'm only considering reply as an Email. So I'm getting hours calculated properly now how do I escalate and assign to the different user? And what is the proper way to do this?

And even if it's possible via apex how I will trigger this code? We are currently using professional Edition so we don't have workflows. Is it possible using apex trigger or process builder?


public class Feed {

    public void demo(){
        List<Case> cases = new List<Case>();
        List<FeedItem> ls = new List<FeedItem>();
        cases = [SELECT Id from Case];
        for(Case c : cases){
            ls = [SELECT Id,type,CreatedDate from FeedItem where Parent.Id = :c.Id AND type = 'EmailMessageEvent'];            
        DateTime d = ls[0].createdDate;
        DateTime nowDateTime = DateTime.now();
        Time startTime = d.time();
        Time now = nowDateTime.time();
        Long calc =  elapsedTime(d, nowDateTime);

    public static Long elapsedTime(DateTime startTime,DateTime endTime) {
        Long dt1Long = startTime.getTime();
        Long dt2Long = endTime.getTime();
        Long milliseconds = dt2Long - dt1Long;
        Long seconds = milliseconds / 1000;
        Long minutes = seconds / 60;
        Long hours = minutes / 60;
        Long days = hours / 24;
        return hours;
  • 1
    remove soql in for loop – cloudZigZag Apr 17 '18 at 17:37
  • Can you schedule batch apex in your edition? I'm working on an answer using batch apex but im not sure of the restrictions on your org – battery.cord Apr 17 '18 at 17:37
  • @battery.cord I even thought of using the scheduler for this but is that proper solution for this scenario? Even if I create the scheduler It must be active 24/7 in the background if I'm not wrong. – Indrajeet Latthe Apr 17 '18 at 17:40
  • @cloudZigZag Thank you for pointing out that, I'm still learning best practices for handling this stuff and this was just test so I wrote that. – Indrajeet Latthe Apr 17 '18 at 17:41
  • Basically, yeah. For something like this, you need to be constantly checking to see if there's any records that now meet the criteria that didn't before. Triggers rely on someone editing them (which if they haven't followed up on the case, they probably aren't editing it either). It doesn't run constantly - you set it up to run at a certain time, and then loop it, essentially. Ie, run this class at midnight daily. – battery.cord Apr 17 '18 at 17:43

Set Up an Escalation Rule. All you need to do is to set up a field that is initially null, and then updated to a non-null value. You can use the Process Builder to assign a value on the first outgoing email or reply, and the rule will disable itself once that field is updated. No code is required, at all.

  • Thank you for a simple solution, If I'm getting it correct this solution will work only for first outgoing Email right? – Indrajeet Latthe Apr 17 '18 at 17:53
  • @IndrajeetLatthe My answer was based on my interpretation of your question. You can take this information and modify it to make it your own. For example, you could modify the process builder to clear the field after another incoming email, etc. You can certainly have it activate continuously until the issue is resolved. – sfdcfox Apr 17 '18 at 17:58
  • Omg, right I think after thinking a lot my brain is not working. Sorry, for that and Thank you again. – Indrajeet Latthe Apr 17 '18 at 18:01
  • I'm trying your solution but I got blank when I tried to add criteria for Process builder, if I choose conditions are met for criteria how can I make criteria for the first outgoing email? I don't see any field in Case as I selected Case for the object. Or I'm missing anything? Or I've to choose different object like FeedItem for process buider to do this? – Indrajeet Latthe Apr 18 '18 at 8:57
  • @IndrajeetLatthe The process builder will need to be for the feeditem or the Email object. – sfdcfox Apr 18 '18 at 13:42

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.