I created a Custom Label and added translation for Spanish. I am calling this Custom Label in the Email Subject Body. How can I implement the translated email depending upon User LanguageLocaleKey?

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 List<String> subj = new List<String>();
 List<String> body = new List<String>();
 String Subject = String.format(System.Label.NotiSubject, subj);
 String messageBody = String.format(System.Label.NotiBody, body);
  • Did you verified the email? Custom labels do automatically translate based on User.LanguageLocaleKey? Jan 29, 2022 at 8:05
  • I triggered an email. But it didn't get translated. There are multiple recipients to the email. Do you want me try individually? Jan 29, 2022 at 8:09
  • Which user context does this class run? guest ? system? Jan 29, 2022 at 8:10
  • I tried using single recipient. Still not getting translated. I am not sure what you meant by user context but to give a gist, I am querying over a custom object records and then sending them to a specific queue member based on the record. For the moment, I am calling the class from anonymous window. Jan 29, 2022 at 8:16
  • 1
    @SachinHooda Okay Now I got it. So the locale depends on the user who is calling the class not the recipients Jan 29, 2022 at 9:47

1 Answer 1


You can use Visualforce Template to achieve that. Here is a link might help you https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messaging_emailTemplate.htm.

Use this method to generate email content dynamically in apex class renderStoredEmailTemplate(templateId, whoId, whatId)

TemplateId => Visualforce Template Id WhoId => Recipient ( Lead/Contact/User ) WhatId => The record you want to use to display email content dynamically.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .