0

When I execute my test class of " trigger class" on case object this error message is received:

first error: FIELD_INTEGRITY_EXCEPTION, You can’t set an entitlement process' start time after any case milestone completion dates.: [SlaStartDate]

This happen when the test class execute the milestone completion Method

This is the simplified code:

public static void caseToValidationOfRequestStatus(List<Case> lstNew, List<Case> lstOld){

    list<Id> lstCase = new list<Id>();

    if(!lstOld.isEmpty()){
        for(Integer i = 0; i < lstNew.size(); i++){
            if(lstNew[i].status != lstOld[i].status && lstNew[i].status == '02' ){
                lstCase.add(lstNew[i].Id);
            }
        }

        if(lstCase.isEmpty() == false){
            completeMilestone(lstCase,System.label.SERV_COL_MilestoneWaitingForDocument, System.today());
        }
    }
}

Public static void completeMilestone(List<Id> caseIds, String milestoneName,DateTime complDate){
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate 
                                       from CaseMilestone 
                                       where caseId in :caseIds and MilestoneType.Name =: milestoneName and completionDate = null limit 1];

    if (cmsToUpdate.isEmpty() == false){
        for (CaseMilestone cm : cmsToUpdate){
            cm.completionDate = complDate;
        }
        update cmsToUpdate;
    }
}

In my test class I am only set the criterias to advance status and update.

@isTest
public class SERV_COL_CaseServiceTest {

    public static list<Account> accTest;
    public static list<Contact> conTest;
    public static list<Case> casTest;
    public static list<SERV_COL_TopicFiled__c> tfTest;
    public static list<SERV_COL_TopicDocument__c> tdTest;
    public static list<SERV_COL_Document__c> docTest;
    public static Entitlement entTest;

    @testSetup static void setupData(){
        accTest = SERV_COL_TestDataFactory.createAccounts(1);
        insert accTest;
        docTest = SERV_COL_TestDataFactory.createDoc('Denuncia por pérdida de tarjeta',true,1);
        insert docTest;
        tfTest = SERV_COL_TestDataFactory.createTopFil('Billetes falsos',true,1);
        insert tfTest;
        tdTest = SERV_COL_TestDataFactory.createTopDoc(docTest[0].Id, tfTest[0].Id,1);
        insert tdTest;
        entTest = SERV_COL_TestDataFactory.createEntitlement(accTest[0].Id);
        insert entTest;
        System.debug('--Ent-->'+entTest);
        casTest = SERV_COL_TestDataFactory.createCase(accTest[0].Id,tfTest[0].Id,1);
        insert casTest;

    }

    @isTest static void advanceCaseStatusTest1(){
        Test.startTest();
            case cas = [SELECT status,SERV_COL_TopicFiled__c FROM case limit 1];
            cas.status = '02';
            update cas;
        Test.stopTest();
    }    
}

I hope can you help me.

1 Answer 1

2

After several test I found the solution to the error, which is caused per not set the field SlaStartdDate in the case estructure in the SERV_COL_TestDataFactory.createCase(); Is necessary to set a value to this field in the estructure that you make for case. Example:

public static list createCase(Id accId,Id tfId, Integer casQty){

    List<Case> lstCase = new List<Case>();
    if(casQty > 0){
        for(Integer i=0;i<casQty;i++){
            Case caseObj = new Case();
            caseObj.AccountId = accId;
            caseObj.Status = '02';
            caseObj.Origin = '01';
            **caseObj.slaStartDate=system.now();**
            caseObj.SERV_COL_TopicFiled__c = tfId;
            lstCase.add(caseObj);
        }
    }
    return lstCase;

}

I hope this solution can help others with the same problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .