How to use custom label with dynamic val ...

How to use custom label with dynamic value?

Jul 10, 2023

We have many situations where a string message that we are displaying to the user may have the dynamic value that we want to hold dynamically at the run time.

This can be easily handled in the Salesforce using the custom label which can not only hold the string but also addresses the dynamic values that you want to capture.

//Custom label used here Test_DynamicLabel which consist of text like
// Hello {0}, how are you, your friend is here and their name is {1}. Can you please Confirm {0}?
String testStringValue = String.format(Label.Test_DynamicLabel, new List<String>{'Sameer', 'Rakesh'});

If you see the {0} or {1} these are the parameters that holds the dynamic values in the custom label.

So the result that will be shown to the user will be as given below.

//Hello Sameer, how are you, your friend is here and their name is Rakesh. Can you please Confirm Sameer?

Hence you can see that the custom label has been dynamically used and displays the text with whatever value we choose to use.

Cheers ✌️

If you like my Post you can buy me a coffee - Here

Gefällt dir dieser Beitrag?

Kaufe Sunil Kumar einen Kaffee

More from Sunil Kumar