Sub topic 3
Lead Field Mapping During Conversion
Assume you know Salesforce navigation, standard objects, basic permissions, Apex, and SOQL. Lead conversion moves data from a Lead into an Account, Contact, and optionally an Opportunity. Field mapping controls where custom Lead fields go.
Map fields before conversion
In Setup, open Object Manager > Lead > Fields & Relationships > Map Lead Fields. Map a custom Lead field to a compatible custom field on Account, Contact, or Opportunity. The destination field must use a compatible data type and must be writable during conversion.
Standard fields have built-in mappings. For example, Lead Company maps to Account Name, and Lead Email maps to Contact Email. Custom mappings preserve information that would otherwise remain only on the converted Lead.
Existing records and duplicate matching
A user can convert a Lead into a new Account and Contact, or select existing records. When matching an existing Account, Salesforce updates that Account with mapped values where permitted. Selecting an existing Contact avoids creating a second Contact.
Duplicate rules can warn users or block conversion. Review matching rules, duplicate rules, and required fields together. A duplicate warning does not automatically select the correct existing record.
Conversion settings and permissions
Users need permission to convert Leads and create or edit the target records. Lead settings control whether users can create an Opportunity during conversion and whether they can convert Leads without an Account. Validation rules, required fields, record types, and automation on target objects can also prevent conversion.
Automate assignment and conversion with Apex
Assignment and conversion are separate operations. Apply the active assignment rule when inserting the Lead, then convert it after the owner is set.
Lead l = new Lead(
LastName = 'Lovelace',
Company = 'Analytical Engines Ltd',
Email = '[email protected]'
);
Database.DMLOptions options = new Database.DMLOptions();
options.assignmentRuleHeader.useDefaultRule = true;
l.setOptions(options);
insert l;
LeadStatus status = [
SELECT MasterLabel FROM LeadStatus
WHERE IsConverted = true LIMIT 1
];
Database.LeadConvert conversion = new Database.LeadConvert();
conversion.setLeadId(l.Id);
conversion.setConvertedStatus(status.MasterLabel);
conversion.setDoNotCreateOpportunity(true);
Database.LeadConvertResult result = Database.convertLead(conversion);
System.debug(result.getAccountId());Report on conversion
Query conversion fields for audit reports:
SELECT Id, ConvertedDate, ConvertedAccountId, ConvertedContactId
FROM Lead
WHERE IsConverted = true
ORDER BY ConvertedDate DESCCheck failed conversions in logs and inspect validation rules, duplicate rules, field permissions, required fields, and the converted status value.
Exercise
Why might a valid field mapping still fail during conversion?
Show answer
A duplicate rule, validation rule, required field, record type restriction, or missing permission can block the target record.