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
raz rraz r 

how to cover the casemilestone records in test class

how to cover the casemilestone records in test class 
Raj VakatiRaj Vakati
Refer this link 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_support_milestonetriggertimecalculator.htm

https://salesforce.stackexchange.com/questions/150226/milestone-completion-test-class-not-getting-100-code-coverage
 
@isTest 
private class MilestoneTimeCalculatorTest {
    static testMethod void testMilestoneTimeCalculator() {        
      
        // Select an existing milestone type to test with
        MilestoneType[] mtLst = [SELECT Id, Name FROM MilestoneType LIMIT 1];      
        if(mtLst.size() == 0) { return; }
        MilestoneType mt = mtLst[0];
        
        // Create case data.
        // Typically, the milestone type is related to the case, 
        // but for simplicity, the case is created separately for this test.
        Case c = new Case(priority = 'High');
        insert c;
        
        myMilestoneTimeCalculator calculator = new myMilestoneTimeCalculator();
        Integer actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
        
        if(mt.name != null && mt.Name.equals('m1')) {
            System.assertEquals(actualTriggerTime, 7);
        }
        else {
            System.assertEquals(actualTriggerTime, 5);
        }
        
        c.priority = 'Low';
        update c;
        actualTriggerTime = calculator.calculateMilestoneTriggerTime(c.Id, mt.Id);
        System.assertEquals(actualTriggerTime, 18);
    }
}

 
raz rraz r
with out using myMilestoneTimeCalculator calculator = new myMilestoneTimeCalculator(); how can we cover the CaseMilestones.
Raj VakatiRaj Vakati
Can you give me your code ? 
raz rraz r
I need to cover the below query in my test class

list<case> caselist=[select c.Id,(select id,TargetResponseInHrs,TargetDate from case.casemilestones where MilestoneTypeId in :milestonemap.keyset() and IsCompleted=false  limit 1), c.account.name, c.subject,c.Owner.Name, c.status,c.CreatedDate,c.LastModifiedDate ,c.Case_Severity__c,c.casenumber,c.Priority, c.Status_Number__c,c.Status_priority__c,c.Case_Age__c,c.IsEscalated from Case c  where    c.Owner.Id != : userinfo.getUserID() and c.owner.name=:curUser.Primary_Group__c and c.IsClosed != true order by c.Case_Severity__c,c.Status_priority__c,c.lastmodifieddate desc,c.createddate Limit 100];
please give a sample code.