Technical Document - Lead Automation

Technical document for Lead Optimization 

This document outlines the components created for the Lead Optimization, including an Apex class, validation rules, custom setting, lead assignment rule, custom fields, report and a flow. 

  1. Apex Class: LeadTriggerHandler 

This class handles the link population on lead fields and lead de-duplication. 

Key Methods: 

handleBeforeInsert(List<Lead>): This method retrieves the Record Type ID for "AppExchange" leads and filters the input list, keeping only those leads that match this Record Type. 

After filtering it calls the populateLinks and deduplicateLeads with filtered leads as parameter. 

populateLinks (List<Lead>):  Populate Lead records with application-related links, including AppExchange, testimony, success story, and installation links. These links are retrieved from a JSON configuration based on the "Product of Interest" field on each lead. 

deduplicateLeads (List<Lead>): The deDuplicateLeads method processes a list of Lead records to handle duplicate data based on email addresses and domains. It checks if the lead’s email is valid, searches for related Contact, Lead, and Account records, and updates the lead's relationships accordingly. 

Key Functionality: 

  • Duplicate Detection: 

    • Emails containing "invalid" or "esc" are marked as invalid. 

    • Valid emails are processed to extract domains, which are used to identify related accounts. 

  • SOSL Queries: 

    • Two SOSL searches are performed: 

    • Email Search: Retrieves Contact and Lead records matching the provided emails. 

    • Domain Search: Retrieves Account records based on the domain extracted from the email addresses. 

  • Relationship Mapping: 

    • If an email matches a Contact, the lead is linked to the Contact and Account. 

    • If only a matching domain is found, the lead is linked to the Account. 

    • If a matching lead is found, the lead is linked to the parent lead. 

    • If no matches are found, the lead is assigned to "Lead_Queue". 

 

changeTaskOwner (List<Lead> listLead, Map<Id, Lead> oldMap): The changeTaskOwner method changes the owner of all the open tasks related to a lead when the lead owner changes. 

  1. Custom Setting 

  • Functionality Setting – This is a hierarchical custom setting from SFT Package where we have created a new custom checkbox field called Disable Lead Trigger. This checkbox can switch the trigger on/off for org, profile, or on just the User level.

  1. Flow: Lead Automation 

This flow send an automated email using the template based on the type of lead. It creates a task to contact client if phone number is populated on the lead and a follow-up task to follow up in two days if we don’t get any response to automated email. 

Key Functionality:  

  • Send Automated Email: It fetches email template based on the type of leads and send an automated email to the lead 

  • Create a calling task: It creates a task to research about client and contact them if phone number is present on the lead. 

  • Create a follow-up task: It creates a task to follow-up with client if there is no response on automated email in two days. 

  1. Validation Rules 

  • Lead 

Conversion_Rule: This rule ensure that Company profile and proposed solution on lead is filled before qualifying the lead. 

Disqualification_rules: This rule ensure that Company profile field on lead is populated before unqualifying the leads. 

  • Task 

Completion_Rule: This rule ensure that Lead Qualification and comments field on Task are updated before marking it completed. 

  1. Custom Fields 

  • Lead 

    • Is Invalid 

    • App Exchange Link 

    • Testimony Link 

    • Success Story Link 

    • Installation Link 

    • Calendly Link Display 

    • Company Profile 

    • Proposed Solution 

    • Task Due Date 

  • Task 

    • Lead Qualification 

  1. Queue 

  • Lead Queue – Completely new leads are assigned to this queue. Currently the following users are added in this queue. 

    • Ushank Khanna 

    • Ashish Bansal 

    • Anmol Sehgal 

  1. Lead Assignment Rules 

  • Lead Assignment 2 – This rule assign the incoming leads having Product of interest as “Lending Manager” to Ushank Khanna. 

  1. Report 

  • Overdue Tasks – This is a report in the Public folder that displays all overdue tasks.