
Use Case:
Marie Sloan, a Salesforce Admin, is asked to build a Round Robin assignment tool to assign Survey records to Agent records following a Round Robin way, which means that the total number of Survey records to assign should be divided by the number of Agents, and each Agent should be assigned an equal number of Survey records. For example, if we have 3 Agents and 36 Surveys, each Agent will be asigned exactly 12 Surveys.
Object Model:
To tackle this requirement, let’s first explain the data model required to illustrate this example:
- Custom object called Round_Robin_Assigner__c This is the object that will be used to initiate the Round Robin assignment. The fiels are:
- Name: auto number field with display format: RR-{000}
- Number_of_Agents__c: Rollup-Summary field that counts the number of Agent__c records associated with this Round_Robin_Assigner__c record
- Number_of_Surveys__c: Rollup-Summary field that counts the number of Survey__c records associated with this Round_Robin_Assigner__c record
- Custom object called Agent__c with the following fields:
- Name: auto number field with display format: A-{000}
- User__c: lookup field to the User object
- Round_Robin_Assigner__c: Master-Details field to the Round_Robin_Assigner__c object.
- Custom object called Survey__c with the following fields:
- Name: auto number field with display format: S-{000}
- Tag__c: auto number field without any display format. This field simply represents the tag, or Id of eacj Survet record, it is automatically added to each survey, and no 2 surveys will have the same Tag number. This field will be used to calculate the Assignment_ID__c field below.
- Assignment_ID__c: formula field used to give the assignment ID to each Survey record, based on t he total number of Agents and the Tag on each Survey. More details to follow below.
- Round_Robin_Assigner__c: lookup field to the Round_Robin_Assigner__c object. This is the field that will be filled to assign an Agent to the Survey.
Here is the ERD:

To futher explain what’s going on,
- the main object (1) Round_Robin_Assigner__c is the parent of both:
- the object to assign, in this case (2) Survey__c
- the object to assign to, in this case (3) Agent__c.
In other words, if we want to assign Agent__c records to Survey__c records, first, we create a Round_Robin_Assigner__c record, second, we add to it all the Survey__c records that we want to assign, and third, we add all the Agent__c records that should be assigned to Survey__c records. The Round_Robin_Assigner__c record will hav a button that will launch a flow to assign the Surveys to the Agents in a Round Robin fashion! Simple!
Now, let’s explain the fields on each object…
First, the Round_Robin_Assigner__c object has 2 Rollup-Summary fields that count the number of Agent__c and the number of Survey__c associated with it. The field names are Number_of_Agents__c and Number_of_Surveys__c.


On the Survey__c object:
- The Tag__c field is simply an auto-number field that gives a unique number to the record. The first Survey__c record has Tag__c = 1, and so on.
- The Assignment_ID__c field is the field used to assign the Survey__c to the Agent__c. It is a Fomrula field with this Formula:
1 + MOD(Value(Tag__c), Round_Robin_Assigner__r.Number_of_Agents__c)
This MOD function will take the MOD of (1) the Tag number value of the Survey__c record – we uses the Value() function to take the number value of this auto-number field, and (2) the total number of Agent__c records associated with this Round_Robin_Assigner__c record. So, if we have 5 Agent__c records, and 100 Survey__c records,
- For example, the record wih tag 50 would have 1 + MOD(50,5) = 1 + 50 MOD 5 = 1 + 0 = 1,
- the next record would have 1 + MOD(51,5) = 1 + 51 MOD 5 = 1 + 1 = 2
- the next 1 + MOD(52,5) = 1 + 52 MOD 5 = 1 + 2 = 3
- the next 1 + MOD(53,5) = 1 + 53 MOD 5 = 1 + 3 = 4
- the next 1 + MOD(54,5) = 1 + 54 MOD 5 = 1 + 4 = 5
- the next 1 + MOD(55,5) = 1 + 55 MOD 5 = 1 + 0 = 1
- Etc…
This way, the Assignment_ID__c field will dictate which Survey record goes to which Agent, based on the above math.
Next, we will add a Flow to assign the Agent__c field to the Survey__c records.
Create the Flow:
Create a new Screen Flow, and in it first, create the variable that will hold the Id of the Round_Robin_Assigner__c record that will have the button to launch the flow. Remember, the variable name should exactly be ‘recordId‘ with the letter ‘I’ in a capital case.

To start, let’s create 3 “Get Records” elements:
- Get Assigner: to get the details of the 1 Round_Robin_Assigner__c record that has the Id recordId. Store the variable in the Record Variable sov_Assigner.
- Get Agents: to get all Agent__c records that are children of the above Round_Robin_Assigner__c record. Store the variable in the Record Variable socv_Agents.
- Get Sutveys: to get all Survey__c records that are children of the above Round_Robin_Assigner__c record. Store the variable in the Record Variable socv_Surveys.
- I will only show the screenshots of the first and second “Get Records” elements above.






Now, create 2 Number variables and an Assignment element to assign them values:
- v_Agent_Total_count = {!sov_Assigner.Number_of_Agents__c}. This is the rollup summary field that countsthe number of Agents related to this Round_Robin_Assigner__c record.
- v_Agent_Counter = 1. This will set the counter to 1.



Create the first loop:
- Purpose: loop through all the Agent__c records that are related to the Assigner__c record. For each agent, get all the Survey__c records with an Assignment Id equivalent to the Agent.
- Name: Loop through Agents
- Collection Variable: socv_Agents
- Iteration Direction: First item to last item
- Loop Variable: socv_agents_single


Inside this loop, get the Survey__c records with an Assignment Id equivalent to the Agent. For that, we will use use variable v_Agent_Counter. All these syrveys will be stored in a Record Variable called socv_Specific Surveys.



Create a second loop inside the first loop:
- Purpose: loop through all the Survey__c records with an Assignment Id equivalent to the Agent, and add these to a “Record Variable” to assign them at the end to the Agent.
- Name: Loop through specific Surveys
- Collection Variable: socv_Specific_Surveys
- Iteration Direction: First item to last item
- Loop Variable: socv_Specific_Surveys_single


Inside this second loop, assign the Agent Id to the Agent__c field of the Survey. Then add this Survey to a new Record Variable called socv_Surveys_to_Update. To do so, create the Record Variable, then create an Assignment element to add the single Survey__c record to the socv_Surveys_to_Update.



After exiting the second loop, increase the Agent Counter variable by 1

Finally, update all the Survey__c records at once, using a Record Update element on the socv_Surveys_to_Update record variable.

You can then add a Screen element with any information you want:

And this is the final Flow:

Now, activate the Flow, then add a New Action that calls this Flow from within the Round_Robin_Assigner__c object.


Let’s run thre Assigner! Here is a screen before clicking on the button, and then the result aft.er. Notice that each Survey ois now assigned to a specific Agent!


You can modify the objects based on your requirements, but the idea is the same!
Cheers
Walid
Thank you sir. very helpful.