Editing Auto-completion Resolution Time Milestones with Triggers

Available in: Salesforce Classic

This is part of Developing with the Service Cloud.

Trigger on Case

trigger completeResolutionTimeMilestone on Case (after update) {

	// Cannot be a portal user
	if (UserInfo.getUserType() == 'Standard'){
		DateTime completionDate = System.now();
        	List<Id> updateCases = new List<Id>();
        	for (Case c : Trigger.new){
            	if (((c.isClosed == true)||(c.Status == 'Closed'))&&((c.SlaStartDate <= completionDate)&&(c.SlaExitDate == null)))
	if (updateCases.isEmpty() == false)
		milestoneUtils.completeMilestone(updateCases, 'Resolution Time', completionDate);