Monday, November 14, 2016

What is best practice to refer dynamic custom messages in Visualforce with multi-language support ?

Using Custom Label or OutputField or InputField tag, Platform itself will take care of internationalization. However in some cases, Message needs to be dynamic at the same time it should also support muti-language. In Custom Label, we cannot save dynamic String.
Let’s assume we want to show message something like “DEVELOPERNAME is not authorized to access this page”.
Here, Developername should be dynamically changed in visualforce which supports multilanguage. For each developername, it is not feasible to create custom labels. So below workaround can be used :
Step 1 : Create a Custom Label with text “{0} is not authorized to access this page“. In every language, dynamic value should represented by {0}.
Step 2 : In Controller of Visualforce write something like this :


1String developerName = 'Some DeveloperName';
2String message = String.format(Label.DEVELOPERNA, new String[] { developerName });

No comments:

Post a Comment