You need to sign in to do that
Don't have an account?
INVALID_FIELD_WHEN_USING_TEMPLATE in a batch
Hello all,
I'm developping a batch which send emails to a contact List but it doesn't work and I'm getting all time this error :
[code]
INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []
[/code]
And below, my code :
[code]
List<EmailTemplate> emailTemplateList = [
SELECT Id
FROM EmailTemplate
WHERE DeveloperName = :emailTemplateName
];
List<Messaging.SingleEmailMessage> emailsToSend = new List<Messaging.SingleEmailMessage>();
for(Contact aContact : contactList){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(aContact.Id);
mail.setOrgWideEmailAddressId(oweaMap.get(emailMap.get(aRegion)).Id);
mail.setSubject(mailSubject);
mail.setSaveAsActivity(false);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setCharset('UTF-8');
mail.setTemplateId(emailTemplateList[0].Id);
emailsToSend.add(mail);
}
Messaging.sendEmail(emailsToSend);
[/code]
The error is on the last line : Messaging.sendEmail(emailsToSend);
I've trying in selecting Body, HtmlValue and Subject field on the EmailTemplate object but it doesn't work..
What's wrong please?
I'm developping a batch which send emails to a contact List but it doesn't work and I'm getting all time this error :
[code]
INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []
[/code]
And below, my code :
[code]
List<EmailTemplate> emailTemplateList = [
SELECT Id
FROM EmailTemplate
WHERE DeveloperName = :emailTemplateName
];
List<Messaging.SingleEmailMessage> emailsToSend = new List<Messaging.SingleEmailMessage>();
for(Contact aContact : contactList){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(aContact.Id);
mail.setOrgWideEmailAddressId(oweaMap.get(emailMap.get(aRegion)).Id);
mail.setSubject(mailSubject);
mail.setSaveAsActivity(false);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setCharset('UTF-8');
mail.setTemplateId(emailTemplateList[0].Id);
emailsToSend.add(mail);
}
Messaging.sendEmail(emailsToSend);
[/code]
The error is on the last line : Messaging.sendEmail(emailsToSend);
I've trying in selecting Body, HtmlValue and Subject field on the EmailTemplate object but it doesn't work..
What's wrong please?
This is my code :
All Answers
This is my code :