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
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( != 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.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 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.