Process to Setup Entitlement, Case Milestone and close Milestones with Code on initial Response


Process to Setup Entitlement, Case Milestone and close Milestones with Code on initial Response

If you are working as a Salesforce Support Engineer or Support Manager, Usually you wanted to know ‘How long does it take your team to send initial response to customer cases. Each customer might have specific SLAs on required response times based in their business criticality and type of business, and team managers want to understand how efficient their team is at addressing new issues. 

Step by Step Process to set Up Entitlement and Case Milestone in Salesforce:

Enable Entitlement management:

Go to Setup -> Entitlement Management -> Entitlement Settings
Check the check box ‘Enable Entitlement Management’ to enable this and then save. Once Entitlement Management is enabled, you will see other options on this page like Entitlement Versioning, Entitlement-Related Lookup Filters on Case Fields, Milestone Feed Items, Milestone Tracker Time Settings and Milestone Time Settings.

Entitlement Versioning:       

To keep things simple, we limit the changes you can make to an entitlement process once it’s activated. If you want the option to create and maintain multiple versions of an entitlement process, enable entitlement versioning.
NOTE: Once you enable entitlement versioning, you can't disable it. It stays enabled even if you disable entitlement management. That way, you can always tell which version of an entitlement process you’re working with.

Entitlement-Related Lookup Filters on Case Fields:

You can limit the options that are returned in certain lookup fields on cases. The more items you select, the more specific the results will be.

Milestone Feed Items:

Enable milestone feed items to help support agents monitor activity on records with milestones. This option posts to the feed and the record owner’s profile page when a milestone is completed or violated.

You can learn more about them from the below salesforce Doc.




Steps to Setup milestones and entitlement process:

Create the first response Milestone, create the Entitlement process and add the milestone to the Entitlement process.

Go to Setup -> Entitlement Management -> Milestones -> Click New Milestone 




Set Name = Case Initial SLA, Recurrence Type = No Recurrence and click Save to create the new milestone.

Go to Setup -> Entitlement Management -> Entitlement Processes, create a new Entitlement process for Case. 




Then add the Milestone to an Entitlement process.

Here the first response should be sent within 4 hours of the arrival of the case. So, we have added a Milestone to our Entitlement process with the number of Minutes to Complete Milestone value. Also here in milestone setup we can add actions , what should happens if initial response is not done in specified time / what should happen if mile stone completes within the time.





There are two ways where we can send initial response 1) Case Email Action 2) Case Public Comment.
Here I am going to explain you how to mark Milestone as completed if agent sent an email from case action or Case public comments.
Complete Milestone If Agent Sents Email from case Action:
We need to write after trigger on EmailMessage sObject and update the case milestone date to System.Now(). Below is the piece of trigger I used to complete the milestone on initial response.

trigger EmailMessageTrigger on EmailMessage (after insert) {
     set<Id> caseIds = new set<Id>();
    DateTime completionDate = System.now();
    if(Trigger.isInsert || Trigger.isAfter){
        if (UserInfo.getUserType() == 'Standard'){
           
            for(EmailMessage e:trigger.new){
               
                if(e.Incoming == false){
                   
                   
                    caseIds.add(e.ParentId);
                   
                }
            }
            List<CaseMilestone> c = new List<CaseMilestone>() ;
            for(CaseMilestone cm :[select Id, CompletionDate,CaseId,Case.Contact.Email , Case.SlaStartDate, Case.SlaExitDate,Case.EntitlementId 
                                   from CaseMilestone where CaseId IN: caseIds]){
                                      
                                       if (cm.Case.Contact.Email != null && cm.Case.EntitlementId != null && cm.CompletionDate == null &&
                                           cm.Case.SlaStartDate <= completionDate && cm.Case.SlaStartDate != null && cm.Case.SlaExitDate == null) {
                                              
                                           }
                                       cm.CompletionDate = completionDate;
                                       c.add(cm);
                                   }
            update c;
        }
    }
   
}


Mark Milestone as Completed after Agent Sent Case Comment:
We need to write after trigger on CaseComment sObject and update the case milestone date to System.Now(). Below is the piece of trigger I used to complete the milestone on initial response.
trigger CaseCommentTrigger on CaseComment (after insert) {
   
    set<Id> caseIds = new set<Id>();
    DateTime completionDate = System.now();
    if(Trigger.isInsert || Trigger.isAfter){
        if (UserInfo.getUserType() == 'Standard'){
           
            for(CaseComment cc:trigger.new){
               
                if(cc.IsPublished  == true){
                   
                   
                    caseIds.add(cc.ParentId);
                   
                }
            }
            List<CaseMilestone> c = new List<CaseMilestone>() ;
            for(CaseMilestone cm :[select Id, CompletionDate,CaseId,Case.Contact.Email , Case.SlaStartDate, Case.SlaExitDate,Case.EntitlementId 
                                   from CaseMilestone where CaseId IN: caseIds]){
                                      
                                       if (cm.Case.Contact.Email != null && cm.Case.EntitlementId != null && cm.CompletionDate == null &&
                                           cm.Case.SlaStartDate <= completionDate && cm.Case.SlaStartDate != null && cm.Case.SlaExitDate == null) {
                                              
                                           }
                                       cm.CompletionDate = completionDate;
                                       c.add(cm);
                                   }
            update c;
        }
    }   
}

Also to see the Milestone tracker on you case , below are the steps for both classic and lightning

Classic: Setup --> Customize --> Case --> Case Page Layout --> Select the Layout where you want to add Milestone tracker

> Edit page laout and click 'Feed View' from here and then goto 'Other Tools and Components' section to add Milestone Tracker



Lightning: SetUp --> object Manager --> Case --> Lightning Record Page --> Edit the page and add "Milestone Tracker" wherever you want on the page

 




Post a Comment

0 Comments