Notes
Apex:
// Assuming you have a Lead with the name 'Bank of America'
Lead leadToConvert = [SELECT Id, FirstName, LastName, Company, Status FROM Lead WHERE Company = 'Bank of America' LIMIT 1];
// Check if the lead exists
if (leadToConvert != null) {
// Create an Account object
Account newAccount = new Account(
Name = leadToConvert.Company
// You can set other fields here based on your requirements
);
// Convert the lead to an account
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(leadToConvert.Id);
lc.setAccountId(newAccount.Id);
lc.setDoNotCreateOpportunity(true); // Set to true if you don't want to create an Opportunity
lc.setConvertedStatus('Closed - Converted');
// Perform the conversion
Database.LeadConvertResult lcr = Database.convertLead(lc);
// Check if the conversion was successful
if (lcr.isSuccess()) {
System.debug('Lead converted successfully. Account Id: ' + lcr.getAccountId());
} else {
System.debug('Lead conversion failed: ' + lcr.getErrors()[0].getMessage());
}
} else {
System.debug('Lead with the name "Bank of America" not found.');
}
Flow Builder:
Video
Video does not exists.