List<Lead> leads = [SELECT Id, FirstName, LastName, Company, Status, IsConverted, ConvertedOpportunityId
FROM Lead WHERE IsConverted = true];
for (Lead lead : leads) {
System.debug('Converted lead: ' + lead.FirstName + ' ' + lead.LastName + ' from ' + lead.Company);}
Explanation :
This code will execute a SOQL query to retrieve all leads that have a value of "true" for the IsConverted field, indicating that they have been converted to an opportunity. The code will then iterate over the list of leads and print out the first and last name, company, and other information for each converted lead.
You can modify the SOQL query to include additional fields or add additional filters to narrow down the results. For example, you could add a condition to the WHERE clause to only include leads that were converted within a specific date range, or to exclude leads that have a certain status.
You can also modify the code to perform additional actions on the converted leads, such as updating fields or creating related records. For example, you could use the ConvertedOpportunityId field to retrieve the corresponding opportunity record and update a field on that record.
Comments