function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sunil Kumar 545Sunil Kumar 545 

Hi , lead conversion using apex class.

passing parameter method in(firstname,lastname,email)and query with in contact object email is there means it will show its generate or not create any email it create automatically new contact will create .lead exit covert to contact/account,does not exit means convert contact .successfully...using apex class
bhanu_prakashbhanu_prakash
Hi Sunil,
Mark as best answer, If it resloves !!
Please check below code it works on contact email matchs with lead email it will show error
Trigger leadTrigger on Lead(after insert, after update) {
    Set leadEmails = new Set();
    for (Lead l: trigger.new) {
        if (!l.IsConverted && null != l.email && '' != l.email)
            leadEmails.add(l.email);
    }
    Set contactEmailMatches = new Set();
    for (Contact c: [SELECT Id, Email From Contact where Email IN: leadEmails]) {
        contactEmailMatches.add(c.email);
    }
    for (Lead l: trigger.new) {
        if (!l.IsConverted && !l.OwnerId.startsWith(Schema.SObjectType.QueueSobject.getKeyPrefix())) {
            if (contactEmailMatches.contains(l.email)) {
            } 
        }
    }
}
check these link https://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce/

Mark as resloved if it helps :) :)
Thanks, 
Bhanu Prakash
visit ForceLearn.com​​  (https://www.forcelearn.com)
Akshay_DhimanAkshay_Dhiman
Hi Sunil,

This is for Lead convert try it 
 
   
public static Set<id> ConvertingLead(List<Lead> leadList){
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        Set<id> accId = new Set<id>();
        List<Database.LeadConvertResult> lcr = new  List<Database.LeadConvertResult>();
        for(Lead currentlead: leadList){
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(currentlead.Id); 
            Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
            MassLeadconvert.add(Leadconvert);
        }
        if (!MassLeadconvert.isEmpty()) {
            lcr = Database.convertLead(MassLeadconvert);
        }
        for(Database.LeadConvertResult lll:lcr){
            accId.add(lll.getAccountId());
        }
        return accId;
    }


 

 
if you found this answer helpful then please mark it as best answer so it can help others.   

Thanks 
Akshay