How to Use Dynamic Custom Labels in FLOW

Introduction

Custom labels represent one of the subtle yet incredible features of the Salesforce platform. They act as crucial tools for managing and showcasing static text throughout various components. Imagine the possibilities if we can use dynamic custom labels in Flow. Exciting, isn’t it?

In this tutorial, we will walk you through the steps to pass parameters to custom labels, making your Salesforce flows even more versatile and user-friendly.

This article covers:

Watch the recorded session here

Use Dynamic Custom Labels in FLOW

Sample Use Case to Use Dynamic Custom Labels in FLOW

We have a strict security guidelines in a Salesforce instance, where we want to prevent certain users from editing/ creating records in specific Objects. We have a created OWD, sharing rules and custom permissions to handle the security and want to show error messages when unauthorized users try to create/ update records of objects like Account, Contact, Opportunity etc.

The format of the error message is You are not allowed to Create records on Account. Most of us by now will get an idea of using custom labels to store the message, but if there are multiple objects and different permission on each object (create/ update) we might end up creating multiple custom labels.

Better approach would be to create a custom label with place holders, so that we can dynamically pass parameters to generate the right content.

Creating a custom label with placeholder

For the purpose of this example, we are going to create the below custom label which with two placeholders. Here {0} and {1} are the two place holders.

Custom Label with dynamic placeholder

Replace placeholders in Custom Labels with formulas

Now that we have create the custom label with place holders, we can replace that with dynamic string values.

Create formula in the Flow to replace parameters in Custom Label
Create formula in the Flow to replace parameters in Custom Label

Open the flow where you want to use this custom label and create a resource of type Formula. Give it a name, then Search for Substitute function in the Insert a function text box.

Replace the text in the SUBSTITUTE formula with the custom label you created earlier.

Note: You can search for the label by searching for labels in Insert a resource textbox -> select labels -> then select the label you created.

Next, we are now going to replace the dynamic place holder in the label with the value we want to show, in our case we will enter Create for place holder {0} and Account for placeholder {1}

Example:

Formula SUBSTITUTE({!$Label.DynamicLabel}, ‘{0}’, ‘Create’) will result in the output as You are not allowed to Create records on {1}.

Here the place holder {0} got replaced with the static text Account that we passed in the resource.

Next, if we want to replace the {1} placeholder, we need to add another SUBSTITUTE function around the current formula.

Example:

SUBSTITUTE(SUBSTITUTE({!$Label.DynamicLabel},'{0}’, ‘Create’),'{1}’,’Account’) which will result in the output You are not allowed to Create records on Account.

Learn more about SUBSTITUTE formula from Salesforce documentation here.

Using formula field in Screen Flow

Now that we have a formula that replaces the placeholder in custom label, its time to test it. Use this formula anywhere within your screen flow where you want to show the message.

Use Dynamic Custom Labels in FLOW to show custom error messages
Placing the formula field inside a Display Text of the screen flow.

Demo

Demo of using dynamic custom labels in Flow
Demo of Using dynamic custom labels in FLOW

As you can see from the demo image above, how we were successfully able to populate the parameters in a custom label using flow.

You can read other useful topics on Custom Labels:

Conclusion

In this tutorial, we’ve explored the significant advantages of dynamically populating custom labels within Salesforce flows. By leveraging this technique, we’ve demonstrated how to effectively manage and display dynamic content without the need to create numerous custom labels for similar use cases.

By implementing the above steps we have learned how to use dynamic custom labels in Flow and achieve a scalable solution that enhances the robustness and maintainability of your Salesforce environment. This method reduces redundancy, minimizes errors, and provides a streamlined way to handle multiple similar requirements efficiently.

Feel free to follow the steps in your Salesforce instance and experiment with different complete scenarios.

We welcome your feedback and suggestions in the comments section below. Don’t forget to subscribe to our newsletter for more Salesforce tips and share this article with your fellow developers!

One Comment