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
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: {
        if (!l.IsConverted && null != && '' !=
    Set contactEmailMatches = new Set();
    for (Contact c: [SELECT Id, Email From Contact where Email IN: leadEmails]) {
    for (Lead l: {
        if (!l.IsConverted && !l.OwnerId.startsWith(Schema.SObjectType.QueueSobject.getKeyPrefix())) {
            if (contactEmailMatches.contains( {
check these link

Mark as resloved if it helps :) :)
Bhanu Prakash
visit​​  (
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.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
        if (!MassLeadconvert.isEmpty()) {
            lcr = Database.convertLead(MassLeadconvert);
        for(Database.LeadConvertResult lll:lcr){
        return accId;


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