function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ezhil_kezhil_k 

Send Email in diferrent languages through batch class

I want to send email to contacts according to their preffered language through batch apex:.

Following is my code in batch class:
//
 EmailTemplate emailTemplate =[select Id from EmailTemplate where DeveloperName='testinh_vf_template'];
     
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {newcon.Email};
                mail.setToAddresses(toAddresses);
               // mail.setSubject('CASE MESSAGE' );
                //mail.sethtmlBody(templateText);
                mail.settemplateid(emailTemplate.id);
                system.debug('template:' +emailTemplate.id);
                mail.setTargetObjectId(newcon.id);
                mails.add(mail);


 testinh_vf_template Vf email:

<messaging:emailTemplate subject="Tesing" recipientType="Contact" relatedToType="Contact" 
language="{!RelatedTo.language_code__c}">
<messaging:htmlEmailBody >
<html> 
<tr>
{!$Label.Email_Label}
</tr>

</html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

Issue am facing:
When i run the batch class, i am getting email in english only .

When i try to to test by sending email through workflow email alert, email is recieved in contact's language.

Am i missing something in batch apex..please help me to resolve this.
AshlekhAshlekh
Hi,

I think you dont' need to include "toAddresses" becuuse you are using template and target object id. Please try that way, may be you get success.

And also in your remplate you can use 

<messaging:emailTemplate subject="Support" recipientType="User" relatedToType="Case" language="{!CASE(relatedTo.Case_Language__c,'German','DE','English','EN','French','FR','Italian','IT','Danish','da','Spanish','es','Dutch','nl','Finnish','fi','Portuguese','pt','Swedish','sv','Polish','pl','Norweigian','no','EN')}">