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
Salvatore GomezSalvatore Gomez 

Inbound Email Handler - convert Mailto link to plain text

The inbound email handler below works when the email address in the body is passed as plaintext. However, the email address in the body is usually in the format of an mailto link which prevents the submission of this lead. How can i convert the email address that is contained in the email body to plain text?

global class ProcessJobApplicantEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    String RecordTypeId = '01280000000BWjJAAW';
    String status = 'Open - New';
    String LeadSource ='Referral';
    String SecondLeadSource = 'Online Division';
    String[] emailBody = email.plainTextBody.split('\n', 0);
    String FirstName = emailBody[0].substring(11);
    String LastName = emailBody[1].substring(10);
    String EmailAddress =  emailBody[2].substring(14);
    String Phone = emailBody[3].substring(6);
  
    Lead Lead = new Lead();
    Lead.FirstName=FirstName;
    Lead.LastName=LastName;
    Lead.Phone= Phone;
    Lead.Email=EmailAddress;
    Lead.RecordTypeId= RecordTypeId;
    Lead.status=status;
    Lead.LeadSource=LeadSource;
    Lead.Lead_Source_2__c=SecondLeadSource;
    insert Lead;
    
    System.debug('====> Created lead '+Lead.Id);

    return result;

  }

}

Thanks for your help
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Just take the email address in a string and replace the mailto part using String.replace()
Salvatore GomezSalvatore Gomez
Thanks for your suggestion SalesFORCE_enFORCEr . for some reason this didn't seem to solve my issue, I'm wondering if i need to figure out how to convert this email link as plainText. The email message is all plainText except for the email link; example below.

First Name: Test
Last Name: Test
Email Address: Test@test.com (mailto:Test@test.com)
Phone: 555-555-5555
SalesFORCE_enFORCErSalesFORCE_enFORCEr
You can use IndexOf('com') and String.substring to extract the email address.