Sub topic 2
Building Lead Assignment Rules and Converting Leads
Assume you know basic Salesforce navigation, standard objects, users, queues, and simple Apex and SOQL.
Building lead assignment rules
A lead assignment rule decides who owns a new lead. Create one active rule in Setup > Object Manager > Lead > Assignment Rules. Add rule entries in priority order. Each entry has:
- Criteria, such as
Lead Source equals Web. - An owner, which can be a user or a lead queue.
- An optional email notification.
Salesforce evaluates entries from top to bottom. The first matching entry assigns the owner, so put specific rules before broad fallback rules. A final entry can assign unmatched leads to a general queue.
When assignment rules run
Assignment rules can run when a lead is created through the Salesforce interface if the user selects Assign using active assignment rules. Web-to-Lead uses the active rule automatically. Imports and integrations must explicitly request assignment-rule processing.
Apex does not apply assignment rules by default. Set the DML option before inserting the lead:
Lead l = new Lead(
FirstName = 'Ada',
LastName = 'Lovelace',
Company = 'Analytical Engines Ltd',
Email = '[email protected]',
LeadSource = 'Web'
);
Database.DMLOptions options = new Database.DMLOptions();
options.assignmentRuleHeader.useDefaultRule = true;
l.setOptions(options);
insert l;If a lead goes to the wrong owner, check the active rule, entry order, criteria values, queue membership, and whether the entry was actually invoked.
Converting a lead: what changes
Conversion marks the lead as converted and creates or updates an Account and Contact. Salesforce can also create an Opportunity unless conversion settings or the user disable it. The converted lead remains available for reporting and stores references to the resulting records.
You can convert manually or with Apex. The conversion requires a Lead Status whose IsConverted value is true:
LeadStatus status = [
SELECT MasterLabel FROM LeadStatus
WHERE IsConverted = true LIMIT 1
];
LeadConvert request = new Database.LeadConvert();
request.setLeadId(l.Id);
request.setConvertedStatus(status.MasterLabel);
request.setDoNotCreateOpportunity(true);
Database.LeadConvertResult result = Database.convertLead(request);Use field mapping to move custom lead fields into Account, Contact, or Opportunity fields. During conversion, select existing records when appropriate. Duplicate and matching rules can affect which records Salesforce allows or suggests.
Exercise
A Web-to-Lead record ignores your intended user assignment. What should you check first?
Show answer
Check that the correct assignment rule is active, the matching entry is above broader entries, and the target user or queue is valid.