Harness Custom Settings and Flow for Dynamic Round Robins.

Harness Custom Settings and Flow for Dynamic Round Robins | Automate This!

By

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, see how Warren Walters creates custom Auto Number logic using custom settings and flows. By combining these declarative tools, you can create automation like dynamic round robins and custom record numbering based on record types.


Use case: Conditional auto number and dynamic round robin

We want to create a round robin based on specific field values on the lead record. Instead of doing an assignment for every lead, we only want to do an assignment when a specific lead source is set. For example, when the lead source is set to the web, then a web Auto Number field will be incremented. We can run our round robin lead assignments based on this new field. Implementing round robin this way will allow for more flexibility in your assignment process based on record conditions.

Scenario: Lead round robin

Let’s say your company uses round robin lead assignment but wants specific leads to be sent to specific sales reps who are more familiar with the lead sales process. To do this, you can update the round robin lead assignment to be based on criteria in the lead source and assign the leads to the predefined groups.

Example:
Lead Source = Web → Round robin reps (Rep 2, Rep 4, Rep 5)
All other lead sources with round robin all 5 Reps

Solution: Update custom settings in a flow

What are custom settings?

Custom settings are a setup object that’s used to store custom data. They work similarly to custom objects but are primarily used by admins and developers to hold organization-wide data. You can add fields and data sets (similar to records) that are accessible in automation. Custom settings can be manipulated by a wide range of Salesforce tools and automation, such as formula fields, validation rules, flows, Apex, and SOAP API. Custom setting records are only accessible within Setup, unlike standard and custom objects.

How can custom settings help with conditional Auto Numbers?

We will use a custom setting to hold an org-wide variable of the Auto Number count. Since it’s a custom setting, not a custom Auto Number field, we can control when the counter is incremented. We will then use Flow to increment the counter when specific conditions are met.

Custom settings setup

We need a way to hold the custom Auto Number value controlled by the custom setting for every lead created. Similar to the standard way of creating round robin in Salesforce, we will use custom fields.

Create a custom number field with a descriptive name and description so we know what this field was used for if we review it in the future.

Lead object number field customization screen for Lead Source Web Number.

You can make this value unique so that they cannot have duplicates. Note: By making this a unique value, this may cause automation errors, but it will keep your data clean.

Round Robin formula field

Create a Round Robin field that tells the system to assign each new lead to the next user in order. To do this, we need a formula field that rotates the values based on the number of users in our round robin.

Create a formula field number with a descriptive name and description.

Insert this formula:

MOD(Lead_Source_Web_Number__c,{number_of_users})+1

Example: If you have three users in your round robin, your formula would look like:

MOD(Lead_Source_Web_Number__c,3)+1

When the Lead_Source_Web_Number__c = 6 then round robin field = 1
When the Lead_Source_Web_Number__c = 7 then round robin field = 2
When the Lead_Source_Web_Number__c = 8 then round robin field = 3
When the Lead_Source_Web_Number__c = 9 then round robin field = 1 - back to the start

Set the Blank Field Handling property to ‘Treat blank fields as blank’ so that leads that don’t meet the round robin criteria don’t trigger the assignment rules.

Lead object formula field customization screen for Lead Source Web Round Robin.

Once our automation is set up, this field will be used in the lead assignment rules.

Custom setting

Create the custom setting that will hold the Auto Number count. This value will be incremented by the round robin flow.

Set up the Custom Setting definition in Setup > Custom Settings.

Custom Setting Definition screen displaying an 'Auto Number' label and object name.

Create a number field on the custom setting that will hold the Auto Number count. The default value should be 1 so that the incrementation has a starting point. The starting value can be changed later if needed.

Custom Field Definition Edit screen for Lead Source Web Auto Number, a number field with a description stating it's auto-incremented by the Lead Round Robin flow.

To initialize the custom setting data, click Manage, then New. Enter the starting number for the Auto Number.

Custom setting field value Lead Source Web Auto Number set to 1.

You can always manually update the Auto Number value here if needed from data loads or custom incrementation.

Use lead assignment rules to assign leads to reps to leads

Create lead assignment rules based on the Auto Number incrementation and the round robin field. In this example, we have the custom and standard round robin in the same lead assignment rules.

Lead assignment rule 'Conditional Round Robin', listing various rule entries based on round robin criteria.

Use Flow to increment the custom setting and lead value

To achieve this, we will need two record-triggered flows. A before-save flow is used to update the Lead Source Web Number, and an after-save flow is used to update the custom setting. Both flows are needed because of Salesforce’s order of operations. In order for the lead assignment rules to pick up the Lead Source Web Number, it needs to be updated before the data is committed to the database. The after-save flow is used to update the custom setting once the lead update is complete.

Before-save flow

Create a before-save record-triggered flow that (1) queries the custom setting, (2) checks if the Lead Source is Web, (3) increments the custom setting Auto Number web field by one, and (4) sets the values of the Lead Source Web Number field.

Flow with four main steps, depicting the process of retrieving and updating a lead source Auto Number based on specific criteria.

This flow is only triggered when leads are created, and conditions are added, so it only fires when there is a value in the lead source.

Record-triggered flow on the Lead object with entry conditions and optimization options for fast updates or related records actions.

Element 1: Before we start to increment or make decisions, let’s grab the custom setting that holds the web Auto Number value with a Get Records element.

Flow configuration screen for retrieving Auto Number records, with no filter conditions applied, set to automatically store all fields.

Element 2: We’re going to use a Decision element to check if the lead source is Web. Additional lead sources or decision nodes could be added here if we were incrementing based on additional criteria.

Flow Decision element named Check Lead Source, with an outcome defined as 'Source = Web' where the Lead Source equals 'Web', and a button to add more conditions if necessary.

Element 3: In the Web decision path, we use an Assignment element to increment the custom setting Auto Number web field by one using the add operator.

Flow Assignment element for incrementing an Auto Number custom setting, showing a variable set to increase by a value of 1.

Element 4: Then, we use another Assignment element to set the lead's Web Number field to the custom setting Auto Number field, which was previously incremented in the step above. The lead record that triggered the flow is indicated by $Record global variable.

Flow Assignment element showing a variable assignment to set 'Lead Source Web Number' equal to a value from a custom setting.

Since this is a before-save flow, we do not need to do an update operation on the lead record. Setting the value during the assignment effectively does the same thing.

After-save flow

Create an after-save record-triggered flow. Our automation will update records in addition to the one that triggered the process. Now, we can create a record-triggered flow that will increment the custom setting and update the lead value.

Flow displaying a record-triggered process to get a custom setting Auto Number, check the lead source, and update records based on whether the source is web or a default outcome.

This flow is only triggered when leads are created, and conditions are added, so it only fires when there is a value in the lead source.

Configuration of a record-triggered flow for the Lead object, with conditions set to trigger when the LeadSource field is not null, optimized for actions and related records updates.

Repeat elements 1, 2, and 3 from the before-save flow since they are exactly the same. We need this logic to be the same so that the Auto Number updates on the custom setting will be in sync. There is potential for optimization here, where we can use a sub-flow to use the same logic.

Next, we use an Update Records element to save the custom setting record with the changed Auto Number value.

Flow Update Records element that updates a custom setting, with the selected record for update being 'Auto Number from Get_Custom_Setting_Auto_Number'.

Of course, since we’ve made changes, we need to save and activate the flow.

Let’s test our flow

To test this flow, we can either use flow debug or create leads directly in the sandbox. Using the flow debug feature to test will only show the incrementation and updating of the custom setting, but not the actual lead assignment.

To perform a complete end-to-end test, we will need to test by creating a new lead in the sandbox. When testing in the org, check the ‘Assign using active assignment rule’ box to ensure your assignment rules have run.

Lead record creation screen featuring a description text box and a checked option to 'Assign using active assignment rule'.

Upon save, the Lead Source Web Number field should only be updated when the value in the Lead Source is equal to Web. Then, the Lead Source Web Round Robin field will display the appropriate number for the lead assignment rules.

Let’s recap

We were able to create a custom Auto Number field based on criteria the business decided on, and that allowed for a dynamic round robin lead assignment. This technique of custom Auto Numbers can be applied in many different ways. For example, you can create custom invoice numbers depending on record types.

One question that may arise is, “Why aren’t we using custom metadata types?” As of right now, custom metadata types cannot be updated by a flow. If updating via Flow gets added to custom metadata types in the future, then it would be the preferred setup tool to use in this situation. There’s an idea on the IdeaExchange to update custom metadata types in Flow— please vote on it. You can find all the metadata from this demo in this GitHub repository.

Custom settings considerations

  • Custom settings are a type of custom object. Each custom setting counts against the total number of custom objects available for your organization.
  • Only custom settings definitions are included in packages, not data. This means the Auto Number value does not carry over during deployments.

Resources

Want to see more good stuff? Subscribe to our channel!

SUBSCRIBE TODAY
Use Flows and Experience Cloud to Access Salesforce Scheduler.

Use Flows and Experience Cloud to Access Salesforce Scheduler | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Lynn Guyer requests support from […]

READ MORE