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
Nishit MistryyyNishit Mistryyy 

test class for milestone updation

I have a class called MilestoneUtils and i want to write a test class for it
The code for the class is:
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 completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
        update cmsToUpdate;

//and cm.MilestoneType.Name=:milestoneName
AnkaiahAnkaiah (Salesforce Developers) 
Hi Nishit,

try with below code. you need to query the casemilestone records and update with current caseid in the test data.
public class MilestoneUtilsTest {
    static testmethod void insertcasemethod(){
        Account acc = new account();
        acc.Name ='test acc';
        insert acc;
        Entitlement et = new Entitlement();
        et.Accountid =; ='test ent';
        insert et;
        List<id> caselist = new List<id>();
        case cs = new case();
        cs.Subject ='testing cs';
        cs.Status = 'Escalated';
        cs.Entitlementid =;
        cs.Origin = 'Web';
        insert cs;
        //MilestoneUtils mu = new MilestoneUtils();



If this helps, Please mark it as best answer.

Nishit MistryyyNishit Mistryyy

NO it is covering only 57% of code coverage.. it is not covering following lines

 for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
update cmsToUpdate;

We want minimum of 75%of code coverage