• M Sreekanth
  • NEWBIE
  • 70 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 12
    Replies
Can any one tell me is this my code is handling excetion and if transaction happen then how to navigate to page ,if it it is working properly how to know  and if any modifactions require let me know

Class:-
=====
/*
 * Description        : Bulk Account Creation
 * Autor              :Sreekanth Meesal
 * Created Date       :16/03/2023
 * Last Modified Dtae :
*/
public class Account_Class {
/*
 * Description        : Bulk Account Creation
 * Autor              :Sreekanth Meesal */
    
    public string name{set;get;}
    public string phone{set;get;}
    public string accNo{set;get;}
    public string industry{set;get;}
    
    public pageReference insertAcc(){
        account a = new account();
        a.Name = name;
        a.Phone = phone;
        a.AccountNumber = accNo;
        a.Industry = industry;
        list<account> accList = new list<account>();
        accList.add(a);
        try{
        Database.SaveResult[] srList = DataBase.insert(accList,true);
        for(Database.SaveResult sr:srList){
            if(sr.isSuccess()){
                system.debug('Success Id => '+sr.getId());
            }else{
                for(Database.Error err:sr.getErrors()){
                    system.debug('Message : fields => '+err.getMessage()+' : '+err.getFields());
                }
            }
        }
        }Catch(Exception e){
            system.debug('Message : cause '+e.getMessage()+' : '+e.getCause());
        }
        
        pageReference p = new pageReference('/'+a.id);
        return p;
    }
 
}

Vf Page :-
======
<apex:page controller="Account_Class">
 <apex:form >
 <apex:pageblock title="Accounts Page">
 <apex:pageblockButtons location="Bottom">
 <apex:commandButton action="{!insertAcc}" value="Create"/>
 </apex:pageblockButtons>
 <apex:pageBlockSection columns="2">
  <apex:pageBlockSectionItem >
     <apex:outputLabel value="Account Name"/>
     <apex:inputText value="{!name}"/>
   </apex:pageBlockSectionItem>
   
    <apex:pageBlockSectionItem >    
     <apex:outputLabel value="Account Phone"/>
     <apex:inputText value="{!phone}"/>
   </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
     <apex:outputLabel value="Account No"/>
     <apex:inputText value="{!accNo}"/>
      </apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem >
     <apex:outputLabel value="Industry"/>
     <apex:inputText value="{!industry}"/>
      </apex:pageBlockSectionItem>
 </apex:pageBlockSection>

 </apex:pageblock>
 </apex:form>
</apex:page>
By default apex class will run on system mode(without Sharing) then way without sharing key word is there in apex what is the exact use of it,When it will need.Can any one elaborate with one example please
apex code:-
--------------
public class SOQL_Injection_Ex {
    public string name{set;get;}
    public string phone{set;get;}
    public list<contact> conList{set;get;}
    public void searchMe(){
        //if i did'nt Entered any thing then show me all the the contacts
        string query='Select id,FirstName,LastName,Phone,LeadSource from contact ';
        //if i enterd only LastName and Phone then show me Enterd lastName and phone of the contacts
        if(phone !='' && Name !=''){
        query=query+'Where LastName =\''+name+'\'and phone =\''+phone+'\'';
        }
        //if i enterd only phone then show me Enterd Phone of the contacts
        else if(Phone !=''){
            query=query+'Where Phone =\''+phone+'\'';
        }
       //if i enterd only LastName then show me Enterd lastName of the contacts
       else if(name !=''){
            query=query+'Where LastName =\''+name+'\'';
        }
        conList=DataBase.query(query);
    }
}

VF Page:-
------------
<apex:page controller="SOQL_Injection_Ex">
  <apex:form >
   <apex:pageblock title="Search Contacts">
    <apex:pageBlockButtons location="Bottom">
    <apex:commandButton action="{!searchMe}" value="Search"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection columns="1">
    <apex:pageblockSectionItem >
    <apex:outputLabel value="Enter Name"/>
    <apex:inputtext value="{!name}"/>
    </apex:pageblockSectionItem>
    </apex:pageBlockSection>
    
    <apex:pageBlockSection columns="1">
    <apex:pageblockSectionItem >
    <apex:outputLabel value="Enter Phone"/>
    <apex:inputtext value="{!phone}"/>
    </apex:pageblockSectionItem>
    </apex:pageBlockSection>
    </apex:pageblock>
    <apex:pageBlock title="Contact List">
    <apex:pageBlockTable value="{!conList}" var="c">
    <apex:column value="{!c.LastName}"/>
    <apex:column value="{!c.Phone}"/>
    <apex:column value="{!c.LeadSource}"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
   
  </apex:form>
</apex:page>

If i enterd In phone field this text :- 81273623636 '\''+'And LastName=jso';
User-added image
Scenario:- Create a Map with cityName as key,and its corresponing
======    places as values

Public class Map_Practice{
public static void mapPrac(){
    //*Create a Map with cityName as key,and its corresponing places as values
    Map<string,list<string>> myMap = new Map<string,list<string>>();
        list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
        list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
        list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
            myMap.put('HYD',Hplaces);
               myMap.put('BAN',Bplaces);
            myMap.put('CHE',Cplaces);
        system.debug('City and Its Places'+myMap);
        //Get all the city names
        set<string> keys =myMap.keySet();
         system.debug('Cityes==>'+keys);
        //get all the places
        /* *if my map of values is list<string> then we can get all the values list<list<string>>*/
        list<list<string>> values = myMap.values();
           system.debug('Places==>'+values);  
        } 

}

Please Help Me i am new to salesforce
HandlerClass:-
==========
public class PreventConDuplicatePhoneByAccount {
    public static void fetchDupCon(list<contact> conList){
        for(contact c:conList){
            integer count=[select count() From Account WHERE id=:c.accountId and Phone=:c.Phone];
            if(count!=1){
                c.Phone.addError('Phone No Should Be Same As Linked Account');
            }
        }
    }
}

Trigger  Code:-
==========
trigger PreventConDuplicatePhoneByAccountTrigger on Contact (before insert,before update) {
PreventConDuplicatePhoneByAccount.fetchDupCon(Trigger.new);
}
 
Write a trigger on contact to prevent duplicate records based on Contact Email & Contact Phone.But I want Indivizual Error detection,I did like below
--------------------------------------------------------------------------------------
Heleper Class:-
==========
public class ContactHelper {
//Write a trigger on contact to prevent duplicate records based on Contact Email & Contact Phone.But I want Indivizual Error detection
    public static void PreventDuplicateContacts(list<contact> conList){
        list<string> dupEmail =new list<string>();
        list<string> dupPhone =new list<string>();
        list<contact> EmailList = new list<contact>();
        list<contact> PhoneList = new list<contact>();
        for(contact c:conList){
            dupEmail.add(c.Email);
            dupPhone.add(c.Phone);
        }
        EmailList = [SELECT Id,Email FROM Contact WHERE Email =:dupEmail];
        PhoneList = [SELECT Id,Phone FROM Contact WHERE Phone =:dupPhone];
        for(contact c:conList){
            if(EmailList.size()>0){
              c.Email.addError('Email id already exists');  
            }
            if(PhoneList.size()>0){
              c.Phone.addError('Email id already exists');  
            }
        }
        
    }
}

Handler Class:-
==========
public class ContactHandler {
    public static void PreventDuplicateContacts(){
        ContactHelper.PreventDuplicateContacts(Trigger.new);
       
    }
 
}

Trigger Code:-
=========
trigger ContactTrigger on Contact (Before insert,Before Update) {
    if(Trigger.isInsert){
       ContactHandler.PreventDuplicateContacts();
    }
     else if(Trigger.isUpdate){
        ContactHandler.PreventDuplicateContacts();
    }
}
Line: 11, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactCrTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id a072w00000QiZlGAAV; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Class.ContactCrHandler.contactRelationshipByContact: line 11, column 1 Trigger.ContactCrTrigger: line 4, column 1: []

Trigger Code:=
-------------------
trigger ContactCrTrigger on Contact (after insert) {
    if(trigger.isAfter &&trigger.isInsert){
    ContactCrHandler cr = new ContactCrHandler();
        cr.contactRelationshipByContact(Trigger.new);
    }
     if(trigger.isAfter &&trigger.isUpdate){
    ContactCrHandler cr = new ContactCrHandler();
        cr.contactRelationshipByContact(Trigger.new);
    }
}
TriggerHandler:-
--------------------
public class ContactCrHandler {
    public void contactRelationshipByContact(list<contact> conList){
        list<contact_Relationship__c> crList = new list<contact_Relationship__c>();
        for(contact c:conList){
            if(c.Contact_Relationship_Lookup__c==true){
            contact_Relationship__c cr = new contact_Relationship__c();
                cr.Name=c.LastName;
                cr.Contact__c=c.id;
                crList.add(cr);
            }
            insert crList;
        }
    }
}

Bulk Insertion Code:=
----------------------------
public class BulkDeleteContact {
    public static void m1(){
        list<contact> conList = new list<contact>();
        for(integer i=0;i<300;i++){
            contact c = new contact();
            c.LastName='TestContact'+i;
            c.Phone='9283724738';
            c.Contact_Relationship_Lookup__c=True;
            conList.add(c);
        }
        insert conList;
    }
    public static void deletecon(){
        list<contact> conList=[SELECT id FROM contact WHERE createdDate=today];
        delete conList;
    }
}

Please Help me
My scenario was whenever account record is created then automatically i want to create contact records.it's an interview question i got from yesterday i writtened the logic inside if(Trigger.isAfter&&isInsert)

Trigger:-
-----------

trigger AccountTriggerEx on Account (before insert,after insert) {
/*way it is working both after insert and before insert */
    if(Trigger.isBefore && Trigger.isInsert){
list<contact> conList = new list<contact>();
    for(account a:Trigger.new){
        contact c = new contact();
        c.LastName=a.Name;
        c.AccountId=a.Id;
        c.Phone=a.Phone;
        conList.add(c);
    }
    insert conList;
    }
      if(Trigger.isAfter && Trigger.isInsert){
list<contact> conList = new list<contact>();
    for(account a:Trigger.new){
        contact c = new contact();
        c.LastName=a.Name;
        c.AccountId=a.Id;
        c.Phone=a.Phone;
        conList.add(c);
    }
    insert conList;
    }
}
 
Trigger code:-
-------------------
/* Write a trigger that will prevent a user from creating a lead that already existed as a Contact.
 * We'll use the lead/contacts email address to detect duplicates.
 * Whenever the lead is created or updated.
1. Lead has an email address
2. Try to find a matching contact based or email address.
3. If a match is found, give the user an error.
4. If a match is not found, do nothing.
== if email matched based on contact record in the lead record at the time of creating through an error
*/
trigger DuplicateContactsOnLead on Lead (before insert,before update) {
    for(lead l:Trigger.new){
        if(l.Email != Null){
            list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
            if(con !=null && con.size()>0){
               // string ErrorMsg ='Duplicate Value Found!!';
               // ErrorMsg +='RecordId is:-'+con[0].id;
                l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
             
            }
        }
    }
}
-----------------------------------------------------------------------------------------------------
Test  Class Code:-
--------------------------
@isTest
private class TestClass_DuplicateContactsOnLead {
   
    static testMethod void testme(){
        contact c = new contact(LastName='testing',Email='sreekanth@gmail.com');
        insert c;
        lead l = new lead(LastName='TestLead',Email='sreekanth@gmail.com',Company='wipro',Status='Open - Not Contacted');
        if(l.Email != Null){
            list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
            if(con !=null && con.size()>0){
                l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
        }else{
            insert l;
        }
        }
    }
}
Can any one tell me is this my code is handling excetion and if transaction happen then how to navigate to page ,if it it is working properly how to know  and if any modifactions require let me know

Class:-
=====
/*
 * Description        : Bulk Account Creation
 * Autor              :Sreekanth Meesal
 * Created Date       :16/03/2023
 * Last Modified Dtae :
*/
public class Account_Class {
/*
 * Description        : Bulk Account Creation
 * Autor              :Sreekanth Meesal */
    
    public string name{set;get;}
    public string phone{set;get;}
    public string accNo{set;get;}
    public string industry{set;get;}
    
    public pageReference insertAcc(){
        account a = new account();
        a.Name = name;
        a.Phone = phone;
        a.AccountNumber = accNo;
        a.Industry = industry;
        list<account> accList = new list<account>();
        accList.add(a);
        try{
        Database.SaveResult[] srList = DataBase.insert(accList,true);
        for(Database.SaveResult sr:srList){
            if(sr.isSuccess()){
                system.debug('Success Id => '+sr.getId());
            }else{
                for(Database.Error err:sr.getErrors()){
                    system.debug('Message : fields => '+err.getMessage()+' : '+err.getFields());
                }
            }
        }
        }Catch(Exception e){
            system.debug('Message : cause '+e.getMessage()+' : '+e.getCause());
        }
        
        pageReference p = new pageReference('/'+a.id);
        return p;
    }
 
}

Vf Page :-
======
<apex:page controller="Account_Class">
 <apex:form >
 <apex:pageblock title="Accounts Page">
 <apex:pageblockButtons location="Bottom">
 <apex:commandButton action="{!insertAcc}" value="Create"/>
 </apex:pageblockButtons>
 <apex:pageBlockSection columns="2">
  <apex:pageBlockSectionItem >
     <apex:outputLabel value="Account Name"/>
     <apex:inputText value="{!name}"/>
   </apex:pageBlockSectionItem>
   
    <apex:pageBlockSectionItem >    
     <apex:outputLabel value="Account Phone"/>
     <apex:inputText value="{!phone}"/>
   </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
     <apex:outputLabel value="Account No"/>
     <apex:inputText value="{!accNo}"/>
      </apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem >
     <apex:outputLabel value="Industry"/>
     <apex:inputText value="{!industry}"/>
      </apex:pageBlockSectionItem>
 </apex:pageBlockSection>

 </apex:pageblock>
 </apex:form>
</apex:page>
apex code:-
--------------
public class SOQL_Injection_Ex {
    public string name{set;get;}
    public string phone{set;get;}
    public list<contact> conList{set;get;}
    public void searchMe(){
        //if i did'nt Entered any thing then show me all the the contacts
        string query='Select id,FirstName,LastName,Phone,LeadSource from contact ';
        //if i enterd only LastName and Phone then show me Enterd lastName and phone of the contacts
        if(phone !='' && Name !=''){
        query=query+'Where LastName =\''+name+'\'and phone =\''+phone+'\'';
        }
        //if i enterd only phone then show me Enterd Phone of the contacts
        else if(Phone !=''){
            query=query+'Where Phone =\''+phone+'\'';
        }
       //if i enterd only LastName then show me Enterd lastName of the contacts
       else if(name !=''){
            query=query+'Where LastName =\''+name+'\'';
        }
        conList=DataBase.query(query);
    }
}

VF Page:-
------------
<apex:page controller="SOQL_Injection_Ex">
  <apex:form >
   <apex:pageblock title="Search Contacts">
    <apex:pageBlockButtons location="Bottom">
    <apex:commandButton action="{!searchMe}" value="Search"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection columns="1">
    <apex:pageblockSectionItem >
    <apex:outputLabel value="Enter Name"/>
    <apex:inputtext value="{!name}"/>
    </apex:pageblockSectionItem>
    </apex:pageBlockSection>
    
    <apex:pageBlockSection columns="1">
    <apex:pageblockSectionItem >
    <apex:outputLabel value="Enter Phone"/>
    <apex:inputtext value="{!phone}"/>
    </apex:pageblockSectionItem>
    </apex:pageBlockSection>
    </apex:pageblock>
    <apex:pageBlock title="Contact List">
    <apex:pageBlockTable value="{!conList}" var="c">
    <apex:column value="{!c.LastName}"/>
    <apex:column value="{!c.Phone}"/>
    <apex:column value="{!c.LeadSource}"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
   
  </apex:form>
</apex:page>

If i enterd In phone field this text :- 81273623636 '\''+'And LastName=jso';
User-added image
Scenario:- Create a Map with cityName as key,and its corresponing
======    places as values

Public class Map_Practice{
public static void mapPrac(){
    //*Create a Map with cityName as key,and its corresponing places as values
    Map<string,list<string>> myMap = new Map<string,list<string>>();
        list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
        list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
        list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
            myMap.put('HYD',Hplaces);
               myMap.put('BAN',Bplaces);
            myMap.put('CHE',Cplaces);
        system.debug('City and Its Places'+myMap);
        //Get all the city names
        set<string> keys =myMap.keySet();
         system.debug('Cityes==>'+keys);
        //get all the places
        /* *if my map of values is list<string> then we can get all the values list<list<string>>*/
        list<list<string>> values = myMap.values();
           system.debug('Places==>'+values);  
        } 

}

Please Help Me i am new to salesforce
HandlerClass:-
==========
public class PreventConDuplicatePhoneByAccount {
    public static void fetchDupCon(list<contact> conList){
        for(contact c:conList){
            integer count=[select count() From Account WHERE id=:c.accountId and Phone=:c.Phone];
            if(count!=1){
                c.Phone.addError('Phone No Should Be Same As Linked Account');
            }
        }
    }
}

Trigger  Code:-
==========
trigger PreventConDuplicatePhoneByAccountTrigger on Contact (before insert,before update) {
PreventConDuplicatePhoneByAccount.fetchDupCon(Trigger.new);
}
 
Write a trigger on contact to prevent duplicate records based on Contact Email & Contact Phone.But I want Indivizual Error detection,I did like below
--------------------------------------------------------------------------------------
Heleper Class:-
==========
public class ContactHelper {
//Write a trigger on contact to prevent duplicate records based on Contact Email & Contact Phone.But I want Indivizual Error detection
    public static void PreventDuplicateContacts(list<contact> conList){
        list<string> dupEmail =new list<string>();
        list<string> dupPhone =new list<string>();
        list<contact> EmailList = new list<contact>();
        list<contact> PhoneList = new list<contact>();
        for(contact c:conList){
            dupEmail.add(c.Email);
            dupPhone.add(c.Phone);
        }
        EmailList = [SELECT Id,Email FROM Contact WHERE Email =:dupEmail];
        PhoneList = [SELECT Id,Phone FROM Contact WHERE Phone =:dupPhone];
        for(contact c:conList){
            if(EmailList.size()>0){
              c.Email.addError('Email id already exists');  
            }
            if(PhoneList.size()>0){
              c.Phone.addError('Email id already exists');  
            }
        }
        
    }
}

Handler Class:-
==========
public class ContactHandler {
    public static void PreventDuplicateContacts(){
        ContactHelper.PreventDuplicateContacts(Trigger.new);
       
    }
 
}

Trigger Code:-
=========
trigger ContactTrigger on Contact (Before insert,Before Update) {
    if(Trigger.isInsert){
       ContactHandler.PreventDuplicateContacts();
    }
     else if(Trigger.isUpdate){
        ContactHandler.PreventDuplicateContacts();
    }
}
Line: 11, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactCrTrigger: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id a072w00000QiZlGAAV; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Class.ContactCrHandler.contactRelationshipByContact: line 11, column 1 Trigger.ContactCrTrigger: line 4, column 1: []

Trigger Code:=
-------------------
trigger ContactCrTrigger on Contact (after insert) {
    if(trigger.isAfter &&trigger.isInsert){
    ContactCrHandler cr = new ContactCrHandler();
        cr.contactRelationshipByContact(Trigger.new);
    }
     if(trigger.isAfter &&trigger.isUpdate){
    ContactCrHandler cr = new ContactCrHandler();
        cr.contactRelationshipByContact(Trigger.new);
    }
}
TriggerHandler:-
--------------------
public class ContactCrHandler {
    public void contactRelationshipByContact(list<contact> conList){
        list<contact_Relationship__c> crList = new list<contact_Relationship__c>();
        for(contact c:conList){
            if(c.Contact_Relationship_Lookup__c==true){
            contact_Relationship__c cr = new contact_Relationship__c();
                cr.Name=c.LastName;
                cr.Contact__c=c.id;
                crList.add(cr);
            }
            insert crList;
        }
    }
}

Bulk Insertion Code:=
----------------------------
public class BulkDeleteContact {
    public static void m1(){
        list<contact> conList = new list<contact>();
        for(integer i=0;i<300;i++){
            contact c = new contact();
            c.LastName='TestContact'+i;
            c.Phone='9283724738';
            c.Contact_Relationship_Lookup__c=True;
            conList.add(c);
        }
        insert conList;
    }
    public static void deletecon(){
        list<contact> conList=[SELECT id FROM contact WHERE createdDate=today];
        delete conList;
    }
}

Please Help me
My scenario was whenever account record is created then automatically i want to create contact records.it's an interview question i got from yesterday i writtened the logic inside if(Trigger.isAfter&&isInsert)

Trigger:-
-----------

trigger AccountTriggerEx on Account (before insert,after insert) {
/*way it is working both after insert and before insert */
    if(Trigger.isBefore && Trigger.isInsert){
list<contact> conList = new list<contact>();
    for(account a:Trigger.new){
        contact c = new contact();
        c.LastName=a.Name;
        c.AccountId=a.Id;
        c.Phone=a.Phone;
        conList.add(c);
    }
    insert conList;
    }
      if(Trigger.isAfter && Trigger.isInsert){
list<contact> conList = new list<contact>();
    for(account a:Trigger.new){
        contact c = new contact();
        c.LastName=a.Name;
        c.AccountId=a.Id;
        c.Phone=a.Phone;
        conList.add(c);
    }
    insert conList;
    }
}
 
Trigger code:-
-------------------
/* Write a trigger that will prevent a user from creating a lead that already existed as a Contact.
 * We'll use the lead/contacts email address to detect duplicates.
 * Whenever the lead is created or updated.
1. Lead has an email address
2. Try to find a matching contact based or email address.
3. If a match is found, give the user an error.
4. If a match is not found, do nothing.
== if email matched based on contact record in the lead record at the time of creating through an error
*/
trigger DuplicateContactsOnLead on Lead (before insert,before update) {
    for(lead l:Trigger.new){
        if(l.Email != Null){
            list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
            if(con !=null && con.size()>0){
               // string ErrorMsg ='Duplicate Value Found!!';
               // ErrorMsg +='RecordId is:-'+con[0].id;
                l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
             
            }
        }
    }
}
-----------------------------------------------------------------------------------------------------
Test  Class Code:-
--------------------------
@isTest
private class TestClass_DuplicateContactsOnLead {
   
    static testMethod void testme(){
        contact c = new contact(LastName='testing',Email='sreekanth@gmail.com');
        insert c;
        lead l = new lead(LastName='TestLead',Email='sreekanth@gmail.com',Company='wipro',Status='Open - Not Contacted');
        if(l.Email != Null){
            list<contact> con =[SELECT ID FROM Contact WHERE EMAIL=:L.Email];
            if(con !=null && con.size()>0){
                l.Email.addError('Duplicate Value Found!! Record Id Is:='+con[0].id);
        }else{
            insert l;
        }
        }
    }
}