
trigger ConvertLeads on Account (after insert) {
LeadStatus convertStatus = [
select MasterLabel
from LeadStatus
where IsConverted = true
limit 1
];
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
//Fetch all the Leads with same Company Name
for (Account NewAccount: Trigger.new){
List <lead> LeadsToConvert = [select id,company, name from Lead where company = : NewAccount.name and isConverted = false];
system.debug('LeadstoConvert' + LeadsToConvert);
for (Lead LTC : LeadsToConvert){
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(LTC.Id);
lc.setAccountId(NewAccount.ID);
lc.setConvertedStatus(convertStatus.MasterLabel);
database.LeadConvertResult lcr = Database.convertLead(lc);
}
}
}
10 respuestas
Ines Garcia (get: Agile) Forum Ambassador
Thats more of my confort zone :p
trigger the flow (maybe with process builder?) when a lead is converted,
then hold the account variables you need like ID (so you can map other contacts to it), the name, email etc as you have for matching.
Then loop through all leads that have not being converted where there is a match.
hold them into a collection, then per each item in collection to create the new contacts under that account variable di
have a look at this too for the custom conversion: https://automationchampion.com/tag/auto-convert-lead-using-process-builder/