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
firstqa systemfirstqa system 

lead generation from small email instead of Salesforce generated mail

hello  wrote apex class and created email services but it is only working when i send  the email to the very long sf generated email address and lead is generating but i need to generate lead when i give small  email address like first@gmail.com  

This is my apex code

global class CreateLeadFrmEmail implements Messaging.InboundEmailHandler {
    
     
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {
 
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

       // String subToCompare = 'CreateLead';

       // if(email.subject.equalsIgnoreCase(subToCompare))
        //{
           FirstQA_Leads__c c = new FirstQA_Leads__c();
            c.Name= email.fromAddress;
           c.Description__c=email.plainTextBody;
           c.Lead_Status__c='from email';
           
            insert c;
 
            

 
    result.success = true;
        return result;
    }
 
   
}

kindly help me in this Thanks in advance 

Regards
Syed E H Mazhari 
mazharibobby829@gmail.com 
8328174785
SwethaSwetha (Salesforce Developers) 
HI Syed,
This behaviour is working as designed and there is no workaround. Salesforce generates a unique domain-part for each email service address to ensure that no two email service addresses are identical.

To elaborate, as salesforce does not offer OOTB functionality for Email to lead, you create an email service class in apex using code like below 
global class CreateLeadExample implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){
    // Create an InboundEmailResult object for returning the result of the  
    // Apex Email Service 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    String myPlainText= '';

    // Add the email plain text into the local variable  
    myPlainText = email.plainTextBody;

    // Check for existing leads with this email address   
    Lead[] leads = [SELECT Id, Name, Email
      FROM Lead
      WHERE Email = :email.fromAddress];

    if (leads.size() == 0) {
      // New Lead object to be created - set LastName and Company to
      // dummy values for simplicity
      Lead newLead = new Lead(Email = email.fromAddress, 
        LastName = 'From Email', 
        Company = 'From Email');

      // Insert a new lead
      insert newLead;    

      System.debug('New Lead record: ' + newLead );   
    } else {
      System.debug('Incoming email duplicates existing Lead record(s): ' + leads );    
    }

    // Set the result to true. No need to send an email back to the user      
    // with an error message   
    result.success = true;

    // Return the result for the Apex Email Service 
    return result;
  }
}

After you create Email Service, you will be provided with an option to "add new email address"

During this step, in the email address field, you will only be permitted to specify the local-part(As in below example: service1) of the email address. Salesforce.com assigns the domain name part of the address.

Example: service1@14a1zhmclcbpqrstd8ba7l8y6073hzyoikc5vl7ehg35a5fyx.7f-wxvuaa.ap5.apex.salesforce.com

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Ivory TollersIvory Tollers
A lead generation service(lead generator Belkins.io (https://belkins.io/)) is defined as the use of technological innovations to assemble or create potential prospects in the Internet. It can be a website, or a series of articles, videos, blogs, and other online content that target particular types of prospects. Usually, lead generation services offer a number of options for contacting potential clients. They may provide email addresses to help you send emails to these prospects. They may also provide lead generation tools such as pre-written emails, downloadable content, and other forms of online content that can be used to contact your leads.