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
Natasha Ali 3Natasha Ali 3 

TRIGGER HELP - Add block functionality to existing trigger

Hi, 
I have a trigger that converts a lead into a person account if the compnany name is null (when an application comes into SF). I need to add the functionality to block an application from coming into Salesforce if the email address already exists in Salesforce. Below is the trigger:
 
Trigger AutoConvert on Lead (after insert) {
     LeadStatus convertStatus = [
          select MasterLabel
          from LeadStatus
          where IsConverted = true
          limit 1
     ];
     List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

     for (Lead lead: Trigger.new) {
          if (!lead.isConverted && lead.Company == null) {
               Database.LeadConvert lc = new Database.LeadConvert();
               String oppName = lead.Name;
               
               lc.setLeadId(lead.Id);
               lc.setDoNotCreateOpportunity(true);
               lc.setConvertedStatus(convertStatus.MasterLabel);
               
               leadConverts.add(lc);
          }
     }

     if (!leadConverts.isEmpty()) {
          List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
     }
}
Any help is much appreciated :)
Many Thanks,
Natasha