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
Amit Singh 1Amit Singh 1 

Open Mile Stone When a case turns to Open from Closed Stage

Can some one provide me the code to open the milestone. I have triged the code and getting the error that you can not change the completion date of milestone that already exited the entitlement process.
public static void reopenMilestone(List<Id> caseIds, String milestoneName, DateTime complDate, Map<Id, String> case_Map) {
    System.debug('#### complDate = '+complDate);
    List<Case> caseList = new List<Case>();
    List<Entitlement> ent = [Select Id From Entitlement LIMIT 1];
    List<CaseMilestone> cmsToUpdate = [select Id, startDate, completionDate,MileStoneTypeId, caseId from CaseMilestone cm where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName limit 1];
    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = null;
            cm.startDate =;
        System.debug('#### cmsToUpdate = '+cmsToUpdate);
        System.debug('#### caseList = '+caseList);
        runOnce = true;
        update cmsToUpdate;
Please help me.
AMit SIngh
pranoti patilpranoti patil
Hi Amit,

As error states, you cannot change the milestone completion date for cases that are exited from entitlement process.

Please check your Entitlement process exit criteria from setup -> Entitlement Management -> Entitlement Processes.  Normally case should exit entitlement process when case is closed.

Kindly mark it is as an answer if this resolves your query.