2 answers
Check this one. public class AddLeadSubmissionToLead { public static void addLStoLead (List<Lead> leadsFromTrigger) { //Set<String> nameCompany = new Set<String>(); map<string,id> mapLeadCompanies = new map<string,id>(); List<Lead_Submission__c> listOfLeadsSubs = new List<Lead_Submission__c>(); List<Id> listOfLeadsSubIDs = new List<Id>(); for(Lead nwLead : leadsFromTrigger) { listOfLeadsSubIDs.add(nwLead.Id); //nameCompany.add(nwLead.LastNameStreetAndZipCode__c );
mapLeadCompanies.put(nwLead.LastNameStreetAndZipCode__c,nwLead.id); } List<Lead_Submission__c> ldSub = [SELECT Id, Lead__c, LastNameStreetAndZipCode__c FROM Lead_Submission__c WHERE LastNameStreetAndZipCode__c in:mapLeadCompanies.keyset()]; System.debug('Lead Submission Found ' + ldSub); for(Lead_Submission__c ldsubs : ldSub) { if(ldsubs.Lead__c == null && !ldSub.isEmpty()) { ldsubs.Lead__c = mapLeadCompanies.get(ldsubs.LastNameStreetAndZipCode__c);//listOfLeadsSubIDs[0]; listOfLeadsSubs.add(ldsubs); } } update listOfLeadsSubs; }}