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
ponneri navadeepponneri navadeep 

Test cases for case Milestones

User-added image
how can i cover the code for red lines?

 
Amit VaidyaAmit Vaidya
Hi Ponneri,

Write the not null check and > 1 check in first if only and for else condition satisfy the condition by having milestones.size() = 0.

Thanks,
Amit
ponneri navadeepponneri navadeep
creation of milestone record is not possible in my sandox,it shows dml operation not allowed in this object
 
Amit VaidyaAmit Vaidya
You can just create records by creating an tab for the milestone object and givin the insert permission in OWD.
ponneri navadeepponneri navadeep
any other way is there for creating records in case milestone? i want test class for this batch class?


global class Core_IPS_Entitlement_For_Migrated_Cases implements Database.Batchable<sObject>{

        global Core_IPS_Entitlement_For_Migrated_Cases(){
                   // Batch Constructor
                   
                    
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator([Select id,status,Core_Next_Response_Due_Date__c,BusinessHoursId,AccountId,SlaStartDate,Core_First_Response_Completed__c,SlaExitDate,ContactId,EntitlementID,Core_IPS_Legacy_IPS_ID__c,Core_IPS_GEC_Flag__c from Case where status='Open' And Core_IPS_GEC_Flag__c = false AND Core_IPS_Legacy_IPS_ID__c != Null and recordType.name='IPS Case Create' AND Core_IPS_GEC_Case__c =false Limit 2]);
        //return Database.getQueryLocator([Select id,status,Core_Next_Response_Due_Date__c,BusinessHoursId,AccountId,SlaStartDate,Core_First_Response_Completed__c,SlaExitDate,ContactId,EntitlementID,Core_IPS_Legacy_IPS_ID__c,Core_IPS_GEC_Flag__c from Case where id='50021000000gVKH']);

        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise    
             /*List<case> LstCase =  new List<case>();
            for(sobject s : scope){
            Case c = (case)s;
            system.debug(c);
            LstCase.add(c); 
            }*/
            Core_IPS_CaseTriggerHandler.assignEntitlementToCase(scope);
            //complteActiveMilstone 
            
            //update scope;
            
            for(sobject s : scope){
                Case cs = (case)s;
                if(!cs.Core_First_Response_Completed__c) cs.Core_First_Response_Completed__c=true;
                cs.Core_Next_Response_Due_Date__c = system.now() + 7;
             }
            update scope;
            
            Map<Id,List<CaseMilestone>> CaseMilestoneByCaseId = milestoneUtils.getActiveMileStone(scope);
            List<CaseMilestone> LstCaseMilestoneToUpdate = new List<CaseMilestone>();
            for(sobject s : scope){
            Case cs = (case)s;
            
            //if (milestoneUtils.isCaseMilestoneUpdateRequired(cs, system.now())){
                //cs.Core_Trigger_Next_Response__c=true;
                /*if(!cs.Core_First_Response_Completed__c) milestoneUtils.completeMilestone(cs, mtFst.name, completionDate);
                else milestoneUtils.completeMilestone(cs, mtNxt.name, completionDate);*/
                List<CaseMileStone> milestoneList = CaseMilestoneByCaseId.get(cs.id);
                if(milestoneList !=null)
                {
                if(milestoneList.size()>1){
                }else{
                
                    milestoneList[0].completionDate = system.now() ;
                    LstCaseMilestoneToUpdate.add(milestoneList[0]);
                    //System.debug('Complete DATE : ' + completionDate );
                    //update milestoneList[0];
                }
              }
            //LstCase.add(c); 
            //}
            }
            if(LstCaseMilestoneToUpdate.size() > 0)
            {
                update LstCaseMilestoneToUpdate;
            }
            
            
        }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }
Amit VaidyaAmit Vaidya
Ohh.. Sorry, I did't realize that you are talking about standard object CaseMilestone. Please give me some time to understand it.
ponneri navadeepponneri navadeep
ok amit
 
Amit VaidyaAmit Vaidya
Hi Ponneri,

Please follow below steps to create milestone.

1) Go to Setup->Build->Customize->Entitlement Management->Entitlement Setting
2) Click on continue
3) Enable Entitlement Management checkbox

Once done with the above steps:
1) Again go to Setup->Build->Customize->Entitlement Management->Milestones
2) Click on Continue
3) Create the new Milstone there

Thanks,
Amit
ponneri navadeepponneri navadeep
i want to create casemailstone record using apex
 
Michal KáparMichal Kápar
Hello, i have same problem in my Test class. Cannot test this. Thank you for any ideas how to solve this.
List<CaseMilestone> milestones = [
            SELECT TargetDate, CaseId
            FROM CaseMilestone
            WHERE CaseId IN :cases
        ];
        
        Map<Id, Datetime> milestoneMap = new Map<Id, Datetime>();
        
        for(CaseMilestone rec : milestones){

//<------- Cannot test this line bacause in Test milestones list is always empty. ------->

            milestoneMap.put(rec.CaseId, rec.TargetDate); 

//<------- Cannot test this line bacause in Test milestones list is always empty. ------->
        
}