I am trying to convert multiple leads in apex. Here is the process i am following.
First check there is an account / contact similar to the lead, if there is then assign the accountid in the leadconvert record else leave them blank so that a new account is created.
This works fine, till the point where i dont have a similar account in the system but there are similar leads. For example i have leads with different names but with same company. So now if i convert the lead i have multiple duplicate accounts because when i do a duplicate account check before the conversion, the accounts dont exist and i dont set the setAccountId and when the first leadconvert record gets converted, new account gets created, the second leadconvert record with same company is converted it also creates a new account. Since i am converting multiple leads in list i dont want to be doing the check every leadconvert record just before the conversion for the fear of hitting the governor limits.
Can anyone think of an alternate way to avoid duplicate accounts if there are similar company leads
set
of lead.company - then look through that set usingcontains()
before adding a new leadConvert record