You need to sign in to do that
Don't have an account?
VSK98
Can i use two template 's in the single message and need to call two template's in the batch class
Hi,
I have used one email template in the single messaging and called in the batch class .........Now i need to call another email template in the batch class based on the condition like in start method
for eg: string soql = 'select id , Name from Account where Name = 'siva' ';
string soql 3 = 'select id , Name from Account where Name = 'sivakumar' ';
here i used one email template in the batch class
global class WTPAA_sendReminderwagenoticestoemployees Implements Database.Batchable <sObject> {
global Database.queryLocator start(Database.BatchableContext bc) {
Date d = Date.today();
// String SOQL = 'SELECT Id, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Status__c,WTPAA_Reminder_for_2nd_week__c,WTPAA_Reminder_for_3rd_week__c,WTPAA_Reminder_for_4nd_week__c FROM WTPAA_Wage_Notice__c WHERE (WTPAA_Reminder_for_2nd_week__c OR WTPAA_Reminder_for_3rd_week__c OR WTPAA_Reminder_for_4nd_week__c = :d) AND WTPAA_Status__c = sent ';
String SOQL = 'SELECT Id,WTPAA_Company_Name__c, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Is_same_Employer_Mailing_Address__c FROM WTPAA_Wage_Notice__c WHERE WTPAA_Is_same_Employer_Mailing_Address__c = false';
return Database.getQueryLocator(SOQL);
}
global void execute(Database.BatchableContext bc, List<WTPAA_Wage_Notice__c> wagenotice) {
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
Emailtemplate et = [select id, developername , IsActive from Emailtemplate where developername = 'WTPAA_Reminder_for_2_weeks' AND IsActive = true];
for(WTPAA_Wage_Notice__c w: wagenotice) {
system.debug('size of the list' +wagenotice.size());
// List<String> toAddresses = new List<String>{w.WTPAA_Employee_Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// mail.setToAddresses(toAddresses);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(w.WTPAA_Related_To__r.id);
system.debug('ID of Contact' +w.WTPAA_Related_To__r.id);
mail.setWhatid(w.id);
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('replicastatelabor@gmail.com')) {
mail.setOrgWideEmailAddressId(owa .id);
}
}
system.debug('IDDDDDDDDDDD*******' +et.id);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) {
}
}
please help me out.....................................................................................................
I have used one email template in the single messaging and called in the batch class .........Now i need to call another email template in the batch class based on the condition like in start method
for eg: string soql = 'select id , Name from Account where Name = 'siva' ';
string soql 3 = 'select id , Name from Account where Name = 'sivakumar' ';
here i used one email template in the batch class
global class WTPAA_sendReminderwagenoticestoemployees Implements Database.Batchable <sObject> {
global Database.queryLocator start(Database.BatchableContext bc) {
Date d = Date.today();
// String SOQL = 'SELECT Id, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Status__c,WTPAA_Reminder_for_2nd_week__c,WTPAA_Reminder_for_3rd_week__c,WTPAA_Reminder_for_4nd_week__c FROM WTPAA_Wage_Notice__c WHERE (WTPAA_Reminder_for_2nd_week__c OR WTPAA_Reminder_for_3rd_week__c OR WTPAA_Reminder_for_4nd_week__c = :d) AND WTPAA_Status__c = sent ';
String SOQL = 'SELECT Id,WTPAA_Company_Name__c, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Is_same_Employer_Mailing_Address__c FROM WTPAA_Wage_Notice__c WHERE WTPAA_Is_same_Employer_Mailing_Address__c = false';
return Database.getQueryLocator(SOQL);
}
global void execute(Database.BatchableContext bc, List<WTPAA_Wage_Notice__c> wagenotice) {
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
Emailtemplate et = [select id, developername , IsActive from Emailtemplate where developername = 'WTPAA_Reminder_for_2_weeks' AND IsActive = true];
for(WTPAA_Wage_Notice__c w: wagenotice) {
system.debug('size of the list' +wagenotice.size());
// List<String> toAddresses = new List<String>{w.WTPAA_Employee_Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// mail.setToAddresses(toAddresses);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(w.WTPAA_Related_To__r.id);
system.debug('ID of Contact' +w.WTPAA_Related_To__r.id);
mail.setWhatid(w.id);
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('replicastatelabor@gmail.com')) {
mail.setOrgWideEmailAddressId(owa .id);
}
}
system.debug('IDDDDDDDDDDD*******' +et.id);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) {
}
}
please help me out.....................................................................................................
Declare a global class attribute to store the template name and a constructor reciving the value. You must use global attributes if you want it to retain values when execute method is called.
Hope this help,
Jorge.
This is not what i expect unfortunately..........
Can i used two template in one batch class
- At the constructor
Try to obtain the two email templates, reducing queries.
Use a global Map<String, String> to store the template name and the template Id.
- At the execute method
Use a Map<String,List<Messaging.SingleEmailMessage>> to store the template Ids and the template's corresponding messages list
Invoke Messaging.sendEmail(mailing.get(templateId)) for every map entry (mailing is the map variable)
If you are worried about limits...Salesforce count every single mail is delivered, not the number of times you call sendMail.