0

I am developing the Milestone and Entitlement Process. I have an object Information which has Master-Detailed relationship with the Case object. Assume I have 5 Milestone under a single Entitlement process and say my Milestone-2 is getting triggered because of object Information. I have the below criteria for milestone:

(Case: Case Record Type EQUALS AAA) AND (Case: Category EQUALS BBB) AND (Case: Sub Category EQUALS CCC) 
AND ((Case: Status EQUALS New)) 

I have an Information trigger now I want to take the decision dynamically at run time how to closed Milestone. How can I do that ? Can I make the used of an entry criteria ? Please suggest.

I have the following code to closed the Milestone.

public class MilestoneUtils {
     public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate){
     ..............................
     ..............................

        if (cmsToUpdate.isEmpty() == false){
            for (CaseMilestone cm : cmsToUpdate){
                cm.completionDate = complDate;
            }
            update cmsToUpdate;
        }
    }
}

Also using below query I can get the list of Milestone

SELECT Id, Name FROM MilestoneType where Id IN 
(SELECT MilestoneTypeId FROM CaseMilestone WHERE CaseId IN :caseIds)

Some code from Trigger:

if(caseMap.get(ww.Case__c).recordType.DeveloperName == 'AAA'){
            if(caseMap.get(ww.Case__c).Category == 'BBB'){                   
                if(caseMap.get(ww.ELC_Case__c).SubCategory == 'CCC'){
                    if(ww.status == false){
                        Case cs =  caseMap.get(ww.Case__c);
                        cs.status = ww.status;
                    }
                }
            }
            if(ww.XX == 'Approved' || ww.XX == 'Pending'){
                caseIds.add(ww.Case__c);
                if(ww.status == true){
                    milestoneName = 'YYYYY';
                }
                else if(ww.status == true || ww.IsPriority =='Submitted'){
                    milestoneName = 'XXXXX';
                }
                else if(ww.status == true || ww.IsPriority =='SUCCESS'){
                    milestoneName = 'EEEE';
                }
            }
        }
    }

    if(!caseIds.isEmpty() && milestoneName != null){
        MilestoneUtils.completeMilestone(caseIds, milestoneName, System.now());
    }
}
1
  • howmany milestones will be active at a point of time in the case? Jul 24 '17 at 20:39
0

If you are having single milestone active at one point of time, then, do not pass milestone name as parameter.

public class MilestoneUtils 
{
    public static void completeMilestone(List<Id> caseIds, DateTime complDate) 
    {

        List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                                            from CaseMilestone cm
                                            where caseId in :caseIds and IsCompleted =False
                                            and completionDate = null limit 1];
        if (cmsToUpdate.isEmpty() == false)
        {
            for (CaseMilestone cm : cmsToUpdate)
            {
                cm.completionDate = complDate;
            }
            update cmsToUpdate;
        }
    }
}
2
  • I have many milestones active at the same time. Those are playing for recursion requests.
    – user46657
    Jul 25 '17 at 5:14
  • Nope, This doesn't help to answer my query
    – user46657
    Jul 28 '17 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy