Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class setExams2Expired implements Schedulable {
- global void execute(SchedulableContext ctx) {
- List<Certification__c> objects = [
- SELECT Id, Expiration_Date__c, Exam_state__c
- FROM Certification__c
- WHERE Exam_state__c in ('Active')];
- for(Certification__c c : objects){
- if(c.Expiration_Date__c < date.today()){
- c.Exam_state__c = 'Expired';
- }
- else if(c.Expiration_Date__c == date.today().addDays(+7)){
- c.Day7ExpiryAlert__c = True;
- }
- }
- update objects;
- }
- }
- @isTest
- public class setExams2ExpiredTest {
- @isTest
- public static void ifNotExpired() {
- Account acc1 = new Account(name='Test Account 1',phone='121212', Global_POD__c ='AP');
- insert acc1;
- Account acc2 = new Account(name='Test Account 2',phone='343434', Global_POD__c ='AP');
- insert acc2;
- Contact con1 = new Contact(accountid=acc1.id,lastname='Test Contact 1',email='abcd@gmail.com');
- insert con1;
- Contact con2 = new Contact(accountid=acc2.id,lastname='Test Contact 2',email='efgh@gmail.com');
- insert con2;
- Certification__c c = new Certification__c(Contact__c=con1.id, Name = 'abcd', Expiration_Date__c = Date.today().addDays(+2), Exam_state__c = 'Active');
- insert c;
- Test.startTest();
- setExams2Expired ctx = new setExams2Expired();
- ctx.execute(null);
- System.assertEquals('Active','Active','ifNotExpired doesn't work - meaning an exam is either set to expired when it shouldn't have been or nothing happenend for a certain record');
- Test.stopTest();
- }
- @isTest
- public static void sendEmail(){
- Account acc5 = new Account(name='Test Account 5',phone='787878', Global_POD__c ='AP');
- insert acc5;
- Account acc6 = new Account(name='Test Account 6',phone='898989', Global_POD__c ='AP');
- insert acc6;
- Contact con5 = new Contact(accountid=acc5.id,lastname='Test Contact 5',email='qrstuv@gmail.com');
- insert con5;
- Contact con6 = new Contact(accountid=acc6.id,lastname='Test Contact 6',email='wxyz@gmail.com');
- insert con6;
- Certification__c c = new Certification__c(Contact__c=con5.id, Name = 'efgh', Expiration_Date__c = Date.today().addDays(+7), Exam_state__c = 'Active', Day7ExpiryAlert__c = false);
- insert c;
- Test.startTest();
- setExams2Expired ctx = new setExams2Expired();
- ctx.execute(null);
- System.assertEquals(false, false,'No alert was sent here');
- Test.stopTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement