Round Robin Lead Distribution With Spigots

Next Tutorial: Using Spigot Stamps To Audit Spigot Actions

๐Ÿ” Goal: Round Robin Lead Distribution with Spigots


๐ŸŽฏ Objective

  • Move leads from a staging user (User User) to two other Users (Test User and Security User) in round robin fashion.
  • Leads being moved must:
    • Be owned by User User
    • Have a status of Open – Not Contacted
  • Ensure fair distribution over time.

๐Ÿ—๏ธ Implementation Steps

  1. Create New Spigot:
    • Name: Lead Assignment
    • App Configuration: Primary App Configuration
    • Run Order: 50 (between 0 and 100)
    • Schedule: Always Running
  2. Set Input Records:
    • From Leads
    • Where:
      • Owner = 'User User
      • Status = 'Open - Not Contacted
    • Ordered by: CreatedDate DESC
    • Limit: 3 (to show uneven split behavior)
  3. Add Modifier (Set of User Records):
    • From: User
    • Where:
      • IsActive = true AND Division = 'Sales
      • OrderBy: ID ASC (for consistent assignment order)
      • Limit: 2000 (future-proofing for team growth)
  4. Create Spigot Action:
    • Name: Round Robin Distribute Leads to Users
    • Type: SObject
    • Subtype: Update
    • Action:
      • Update the Lead Owner ID
      • Set OwnerId = Mod1.Id (Mod1 is the set of Sales User Records)

๐Ÿ”„ Expected Behavior

  • On first run (with 3 leads):
    • Test User gets assigned 2 leads
    • Security User gets assigned 1 lead
  • On next run (with 3 new leads):
    • Test User gets assigned 1 lead (now has 3)
    • Security User gets assigned 2 leads (now has 3)
  • Continues alternating to even out total assignments over time.

๐Ÿ’ก Key Insights

  • Round robin works by cycling through the modifier list (users).
  • The ordering of modifiers (users) matters โ€” hence sorting by ID.
  • The setup is abstract and reusable:
    • Could be used to set any field on any object based on similar inputs, modifiers, and actions.
    • Not limited to Leads or Owner asssignment

๐Ÿ“ˆ Results Observed

  • Leads correctly assigned to new users based on create date.
  • Fair, even distribution over multiple runs.
  • The system keeps track of state and rotates through users consistently.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *