You need to sign in to do that
Don't have an account?

Lead convert functionality to exclude Deleted accounts
Currently when a new Lead is created and certain fields match with an existing Account, the Lead will be converted with the matching Account.
However there needs to be a filter not to convert a fresh lead with an account that is set as Deleted (boolean field)
This criteria should probably go somwhere between this code piece. Does anyone have any ideas regarding this?
However there needs to be a filter not to convert a fresh lead with an account that is set as Deleted (boolean field)
This criteria should probably go somwhere between this code piece. Does anyone have any ideas regarding this?
//All accounts that match the lead emails. List<Account> accounts = [SELECT Id , FirstName , LastName , PersonEmail FROM Account WHERE PersonEmail IN: leadEmails]; Map<String, Account> accountsByEmail = new Map<String, Account>(); for(Account account : accounts) { accountsByEmail.Put(account.PersonEmail, account); } //All the leads that need to be converted into new accounts. List<Database.LeadConvert> leadsToConvert = new List<Database.LeadConvert>(); //All the leads that match an existing account. These accounts will be updated and the lead set to converted. Set<Id> existingAccountsForLeads = new Set<Id>(); for (Lead lead : newLeadsById.Values()) { //to prevent recursion if (lead.isConverted == false && lead.Email_already_in_the_system__c == false) { Database.LeadConvert leadConvert = new Database.LeadConvert(); leadConvert.SetLeadId(lead.Id); leadConvert.SetDoNotCreateOpportunity(true); leadConvert.SetConvertedStatus(convertedLeadStatuses[0].MasterLabel); //Check whether an account already exists with this lead's email and name. If one already exists we do not need to convert //to a new account as they are already a customer. We rather need to update the existing record. Account matchingAccount = accountsByEmail.Get(lead.Email); if (matchingAccount != null && matchingAccount.FirstName == lead.FirstName && matchingAccount.LastName == lead.LastName) { leadConvert.SetAccountId(matchingAccount.Id); existingAccountsForLeads.Add(matchingAccount.Id); } leadsToConvert.Add(leadConvert); } }
I have modified your code.
Please replace your code with below code :
v
Please change Deleted__c with original API name of field DELETED on Account.
Let me know if you need more help on this.
Thanks,
Abhishek
All Answers
I have modified your code.
Please replace your code with below code :
v
Please change Deleted__c with original API name of field DELETED on Account.
Let me know if you need more help on this.
Thanks,
Abhishek