The Case Milestones related list on a case detail page displays a list
of milestones that automatically apply to the case due to an
entitlement process.
Salesforce doesn't close the previous active milestone automatically when you are changing the case status and creates a new milestone.
With the help of apex you need to search the active milestone (e.g.Milestone 1) of the Case and update the completion date in the CaseMilestone record.
public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
List<CaseMilestone> cmsToUpdate = [select Id, completionDate
from CaseMilestone cm
where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
if (cmsToUpdate.isEmpty() == false){
for (CaseMilestone cm : cmsToUpdate){
cm.completionDate = complDate;
}
update cmsToUpdate;
} // end if
}
Best Answer
The doc Using the Case Milestones Related List says that
So visit this link To create milestone and entitlement process first.
Documentation