Access Labels in Apex Dynamically

The Summer’23 update of Salesforce has introduced a new feature called Access Labels in Apex Dynamically. This feature allows developers to use the System.Label.get(namespace, label, language) method to get a custom label, optionally specifying a language. This means that developers can now dynamically resolve label names at runtime, including overriding the user’s current language if a translation exists for the requested language.

For example, let’s say you have a custom label called greeting with translations in multiple languages. With this new feature, you can now dynamically access the label in Apex code like this:

String greetingLabel = System.Label.get(null, 'greeting', 'fr');

This code will retrieve the French translation of the greeting label. This can be useful in situations where you need to display information to users in different languages based on their preferences or location.

I hope this helps!

About the blog

SFDCLessons is a blog where you can find various Salesforce tutorials and tips that we have written to help beginners and experienced developers alike. we also share my experience and knowledge on Salesforce best practices, troubleshooting, and optimization. Don’t forget to follow us on:

Newsletter

Subscribe to our email newsletter to be notified when a new post is published.

Advertisements
Advertisements

Arun Kumar

Arun Kumar is a Salesforce Certified Platform Developer I with over 7+ years of experience working on the Salesforce platform. He specializes in developing custom applications, integrations, and reports to help customers streamline their business processes. Arun is passionate about helping businesses leverage the power of Salesforce to achieve their goals.

Leave a Reply