Created
February 28, 2018 22:47
-
-
Save winniecluk/07141dde09b4327601601a8bf3b05fad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String etFirstWarning { | |
get { return [SELECT DeveloperName, Subject, Body FROM EmailTemplate WHERE DeveloperName = 'invoiceFirstWarning' LIMIT 1].Body;} | |
set { etFirstWarning = value;} | |
} | |
public String etSecondWarning { | |
get{ | |
return [SELECT DeveloperName, Subject, Body FROM EmailTemplate WHERE DeveloperName = 'invoiceSecondWarning' LIMIT 1].Body; | |
} | |
set{ etSecondWarning = value; } | |
} | |
public void saveEmailSettings(){ | |
String s1 = etFirstWarning; | |
String s2 = etSecondWarning; | |
accounting_Controller.updateEmailTemplates(new List<String>{s1, s2}); | |
if (emailService.Boolean_Value__c != emailServiceCurrentSetting){ | |
if (emailService.Boolean_Value__c == false){ | |
String jobId = Setting__c.getInstance('Email Service').Text_Value__c; | |
if (String.isNotBlank(jobId) ){ | |
System.abortJob(jobId); | |
} | |
System.debug('aborted job'); | |
} else { | |
scheduleReminder sr = new scheduleReminder(); | |
String sch = '0 0 23 * * ? *'; | |
String jobId = System.schedule('Daily Email', sch, sr); | |
emailService.Text_Value__c = jobId; | |
System.debug('started job: ' + jobId); | |
} | |
} | |
upsert emailService; | |
if (invoiceMeta1.Text_Value__c.length() > 255 || invoiceMeta2.Text_Value__c.length() > 255){ | |
apexPages.addMessage( new apexPages.Message(apexPages.severity.info,'Length of invoice message must be 255 characters or fewer.')); | |
} else { | |
upsert invoiceMeta1; | |
upsert invoiceMeta2; | |
} | |
} | |
@future | |
public static void updateEmailTemplates(List<String> emailMessages){ | |
List<EmailTemplate> etList = [SELECT DeveloperName, Subject, Body FROM EmailTemplate WHERE DeveloperName = 'invoiceFirstWarning' OR DeveloperName = 'invoiceSecondWarning']; | |
System.debug('these are the updated strings'); | |
System.debug(emailMessages); | |
for (EmailTemplate et : etList){ | |
if (et.DeveloperName == 'invoiceFirstWarning') et.Body = emailMessages[0]; | |
else if (et.DeveloperName == 'invoiceSecondWarning') et.Body = emailMessages[1]; | |
} | |
update etList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment