A Salesforce Apex invocable action for converting leads to accounts, contacts, and opportunities. Designed for use in Salesforce Flows with full parameter flexibility.
- Convert leads with a single action in Flow
- Merge into existing accounts and contacts
- Custom opportunity naming
- Optional opportunity creation skip
- Owner assignment with notification emails
- Bulk conversion support
- Auto-detection of converted status
- Comprehensive error handling
- Bypass duplicate detection rules
- Salesforce CLI installed
- Authenticated to your target org
# For production/developer org
sf org login web -a MyOrg
# For sandbox
sf org login web -a MySandbox -r https://test.salesforce.com# Deploy to default org
sf project deploy start
# Deploy to specific org
sf project deploy start -o MyOrg
# Deploy with verbose output
sf project deploy start -o MyOrg --verbose
# Validate only (no actual deployment)
sf project deploy start -o MyOrg --dry-run# Run tests to verify
sf apex run test -n LeadConverterInvocableTest -o MyOrg -r human- Open Setup > Flows
- Create or edit a Flow
- Add an Action element
- Search for "Convert Lead" in the action search
- Configure the input variables
- Store the output variables for use in your Flow
[Get Lead Record] → [Convert Lead Action] → [Decision: Is Success?] → [Next Steps]
| Variable | Type | Required | Description |
|---|---|---|---|
Lead ID |
ID | Yes | The ID of the lead to convert |
Account ID |
ID | No | Existing account ID to merge into. Creates new account if not provided |
Contact ID |
ID | No | Existing contact ID to merge into. Must be associated with the specified account |
Converted Status |
Text | No | Lead status value for converted lead. Auto-detects if not provided |
Opportunity Name |
Text | No | Name for the new opportunity. Defaults to lead company name |
Do Not Create Opportunity |
Boolean | No | Set to true to skip opportunity creation |
Owner ID |
ID | No | Owner for new records. Defaults to lead owner |
Send Notification Email |
Boolean | No | Send email notification to new owner |
Overwrite Lead Source |
Boolean | No | Overwrite LeadSource on target contact when merging |
Bypass Duplicate Rules |
Boolean | No | Set to true to bypass duplicate detection rules during conversion |
| Variable | Type | Description |
|---|---|---|
Account ID |
ID | The ID of the created or merged account |
Contact ID |
ID | The ID of the created or merged contact |
Opportunity ID |
ID | The ID of the created opportunity (null if skipped) |
Is Success |
Boolean | Whether the conversion was successful |
Error Message |
Text | Error details if conversion failed |
Lead ID |
ID | The original Lead ID (returned on both success and failure) |
Only the Lead ID is required. The action will:
- Create a new Account (using Lead's Company name)
- Create a new Contact (using Lead's name and details)
- Create a new Opportunity (using Lead's Company name)
- Auto-detect the converted status
Set the Account ID to merge the lead into an existing account instead of creating a new one.
Set Do Not Create Opportunity = true to convert the lead without creating an opportunity.
Set Opportunity Name to override the default opportunity naming (which uses the lead's company name).
Set Owner ID to assign the converted records to a specific user. Enable Send Notification Email to notify them.
Provide both Account ID and Contact ID to merge the lead into existing records. The contact must belong to the specified account. Enable Overwrite Lead Source to update the contact's LeadSource field.
Set Bypass Duplicate Rules = true to force conversion even when duplicate detection rules would normally block it. This uses Database.DMLOptions.DuplicateRuleHeader.allowSave to bypass the org's duplicate rules.
The action uses partial success mode, meaning:
- Each lead conversion is independent
- Failed conversions don't block successful ones
- Check
Is Successoutput for each result Error Messagecontains details for failures
Common error scenarios:
- Lead already converted
- Invalid Account/Contact ID
- Contact not associated with specified Account
- Missing required fields on Lead
- Duplicate detected (use
Bypass Duplicate Rulesto override)
Note: The Lead ID output is always returned, even when conversion fails. This allows you to identify which lead caused the error in your Flow's error handling path.
This package uses Salesforce API version 63.0 (Spring '25).
lead-converter/
├── force-app/
│ └── main/
│ └── default/
│ └── classes/
│ ├── LeadConverterInvocable.cls
│ ├── LeadConverterInvocable.cls-meta.xml
│ ├── LeadConverterInvocableTest.cls
│ └── LeadConverterInvocableTest.cls-meta.xml
├── sfdx-project.json
└── README.md
MIT