Every once in a while, you’ll need to use static variables in a Salesforce automation. These variables may be different in sandboxes and in production. But once they are set in a sandbox, they don’t change often.
To illustrate the option, imagine a simple example where we want to assign accounts to a specific user. Here are 3 ways this can be accomplished using a record-triggered flow.
Level 1: Hardcode directly in the step
This is definitely the easiest method to build. You just need to add a “New Update Records” element and set OwnerId to the 18 character UserId.
However, in the future, when the owner changes, you need to find all the flows that reference the old UserId and update it to the new UserId. In each flow, you’ll also need to find the specific element(s) that use the old UserId.
Not surprisingly, this option is a bad idea, as it lacks scalability.
Level 2: Create a constant
One level higher up is to use a flow constant. Note: I like defining constants using upper case lettering, to distinguish it from regular variables.
The process is similar to above, only you first create a constant such as DEFAULT_ACCOUNT_OWNERID and then use this constant in the “New Update Records” element.
When the owner changes, you only need to update it once per flow. This is a good enough option for smaller Salesforce implementations.
Level 3: Use custom settings
The most scalable option is to use custom settings. This means first creating the setting, say, “Organizational Settings” and then adding the field “Default Account Owner Id”.
In the flow, you reference the custom setting field. This is ideal for larger implementations as you only need to change the field once for all flows.
The takeaway
Building scalable functionality is a core component of a good enough Salesforce consultant. The level of technical complexity and scalability depends on the size of the instance, but it’s a good idea not to take the easiest option to develop.