samedi 5 septembre 2020

Else if part getting skipped Salesforce Apex

I wrote this class with a method that sends an email from Sendgrid based on each template id. It works fine except, I have an if else statement which only runs the if and else part and not the else if. The email for the if condition and the else condition are correct. But the emails for the else if condition are getting sent using the template for the else condition. What am I missing here?

public class MailService {

public static final String CASE_CLOSE_3_DAYS_BEFORE_DEADLINE = 'd-236cee9e85f94e219a3f595ad8224a25';
public static final String CASE_CLOSE_1_WEEK_AFTER_DEADLINE = 'd-f9736104d9ba410c9ae2748ea53b2def';
public static final String CASE_CLOSE_30_45_DAYS_AFTER_DEADLINE = 'd-47e918c9be19417eb61699a205b5ed83';
public static final String CASE_CLOSE_60_DAYS_AFTER_DEADLINE = 'd-ad66132fb5ef4eb9b6cbb624b7ee8edb';
public static final String CASE_CLOSE_CONSULTANT_EMAIL_DAY67 = 'd-6587bdc25c4542d89095a212e6ee9d8a';


    public static void sendEmailCaseCloseEmployer(Id jobId, String jobTitle, Datetime deadline, String contactName, String email){
        Date threedaysbefore = Date.today().addDays(3);
        Date oneweekafter = Date.today().addDays(-7);
        Date thirtydaysafter = Date.today().addDays(-30);
        Date fortyfivedaysafter = Date.today().addDays(-45);
        Date sixtydaysafter = Date.today().addDays(-60);
        Date deadlinedate = deadline.Date();
        List<String> postEmails = new List<String>();
          if(!String.isEmpty(email)){ 
            postEmails.add(email); 
          }
        Map<String, Object> templateData = new Map<String, Object>{
            'id' => jobId,
            'jobTitle' => jobTitle,
            'contactName' => contactName,
            'submissionDeadline' => deadline.Date()
        };
        if(deadlinedate==threedaysbefore) {
            SendgridService.send(postEmails, CASE_CLOSE_3_DAYS_BEFORE_DEADLINE, templateData);
        } else if(deadlinedate==oneweekafter) {
            SendgridService.send(postEmails, CASE_CLOSE_1_WEEK_AFTER_DEADLINE, templateData);                
        } else if(deadlinedate==thirtydaysafter||deadline.Date()==fortyfivedaysafter) {
            SendgridService.send(postEmails, CASE_CLOSE_30_45_DAYS_AFTER_DEADLINE, templateData);                
            } else {
            SendgridService.send(postEmails, CASE_CLOSE_60_DAYS_AFTER_DEADLINE, templateData);      
         }      
    }

}

Aucun commentaire:

Enregistrer un commentaire