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
Harshitha BHarshitha B 

Testclass for Sending an email before x days and update the opportunity stage

Hi All, 

I am unable to proceed with the Test class for one of my batch class implemented recenlty.
Batch class Implementation: batch will process the opportunity records, based on the values which is stored in custom metadata types. I am sending an email before x days of closure and update the stage based on the value which is in the custom metadata types.

Logic implemented for sending email before x days:
Date sendEmailDate= opportunityVar.CloseDate .addDays( Integer.ValueOf(mdtVar.STS_Expected_Awarded__c - mdtVar.STS_Notify_Before__c))

IF(System.today() == sendEmailDate){
// logic to send an email
}

I am not able to cover this lines in the test class, below are the things I implemented in test class.
Integer days = Integer.valueOf(mdtVar[0].expectedAwardDate - mdtVar[0].notifyBefore);
oppVar.Closedate = system.today() +days;

the above result value is CloseDate > today()

Scenerio 2:
Integer days = Integer.valueOf(mdtVar[0].expectedAwardDate + mdtVar[0].notifyBefore);
oppVar.Closedate = system.today() -days;

the above result value is CloseDate < today() 
please suggest how to proceed further.

Thanks.