In Part 1 of this series, we explored how to implement Lead-to-Account (L2A) matching including a data normalization algorithm in Salesforce to streamline lead routing and improve operational efficiency.
But what happens when no L2A match is found? In this Part 2 article, we’ll walk through the next step: using a combination of Flow and custom metadata types (CMTs) to define geo-based routing rules, ensuring leads are assigned to the correct owner based on region, lead source, or other criteria.
Why Use Flow and Custom Metadata Types for Lead Routing?
By leveraging Flow and custom metadata types, organizations can:
- Eliminate Excessive Code: Perform both L2A matching and geo-routing declaratively in Flow.
- Increase Flexibility: Allow admins to update routing rules without deploying code changes.
- Ensure Scalability: Handle both L2A matches and geo-routing scenarios seamlessly.
- Simplify Maintenance: Centralize routing rules in custom metadata for easier updates.
Designing the Solution
Step 1: Define the Custom Metadata Type
Create a custom metadata type called Lead_Routing_Rule__mdt with the following fields:
- Region (Text): The geographic region (e.g., "North America," "EMEA").
- Lead Source (Picklist): The lead source (e.g., "Web," "Event").
- Assigned Owner (Text): The user ID or queue ID to which leads meeting the criteria will be routed.
- Index (Number): The index enables prioritizing one rule over another when multiple rules could apply, by controlling the sort order of the metadata query.
- Active (Checkbox): A checkbox to enable or disable the rule for easier maintenance.
Step 2: Create a Flow to Handle L2A Matching and Geo Routing
- Trigger the Flow: Build a Record-Triggered Flow that runs on lead creation or update.
- Normalize Data for Matching: Add Apex actions to normalize fields like Company Name, Website, Address, and Phone using an invocable Apex class. These normalized values are stored temporarily in the Flow for matching purposes.
- Perform L2A Matching: Use a Flow Decision element to compare the normalized lead values with normalized account fields (stored on Account records). This matching can be done entirely declaratively by using Get Records elements to query Accounts. Be sure to sort the collection by Index and use a limit of 1, so only the 1 top-indexed result will be the rightful outcome.
- If a Match is Found: Assign the lead to the owner of the matched account.
- If No Match is Found: Proceed to geo-routing.
- Query Custom Metadata for Routing Rules:
- Add a Get Records element to query Lead_Routing_Rule__mdt.
- Filter the rules based on region, lead source, and active status.
- Sort the results by priority to ensure the highest-priority rule is selected.
- Assign the Owner: Use an Assignment element to update the lead’s owner based on the queried rule.
- Update the Lead Record: Use an Update Records element to save the owner assignment to the lead.
Example Flow Structure
Here’s a high-level view of how the Flow is structured:
- Trigger: Lead creation or update.
- Normalization (Apex): Normalize lead data (Company Name, Address, Phone, etc.).
- L2A Matching:
- Use Get Records to search for Accounts with matching normalized values.
- Use a Decision element to check if a match exists.
- Decision:
- L2A Match Found: Assign lead to the account owner.
- No Match Found:
- Query custom metadata for routing rules.
- Assign the lead owner based on the rule.
- Update Records: Save the lead with the new owner assignment.
Benefits of This Approach
By keeping both L2A matching and geo-routing in Flow, you:
- Minimize Apex Usage: Only normalization logic remains in code, while routing is fully declarative.
- Increase Admin Control: Allow admins to update both matching rules (via normalized fields) and geo-routing rules (via custom metadata).
- Simplify Maintenance: Centralize all routing configurations in metadata and declarative tools.
- Support Scalability: Enable seamless handling of both account-matched and unmatched leads without complex development efforts.
Conclusion
This two-part series has equipped you with the tools to optimize lead routing in Salesforce. By integrating L2A matching and geo-routing using Flow and custom metadata, you can ensure leads are always routed to the right owner, improving efficiency and customer experience.
Comments