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
sainath chalamcherla 9sainath chalamcherla 9 

custom email services

I have to create a lead record, with the values getting in the email body.
Email body has defined template like as below

Dear Team,

The following has been generated : oerdfY

Customer Name : abc xyz

Email address : abcxyz@gmail.com

Phone number : +12345678910

Date of birth : 1985- 04-11

You can review this further on : www.salesforce.com/oerdfY (Hyperlink)

From the above I need to get the customer name , phone number, Email address and DOB and should be mapped to lead as below

Lead.firstName = ABC
Lead.LastName = xyz
Lead. Phone  = 12345678910
Lead.EmailAddress = abcxyz@gmail.com
Lead.dateofbirth = 1985- 04-11

Lead should be inserted.

Only challenge i am seeing here, how to get the customer name, phone number,Email address, DOB from email Body since all are coming as single string, 

how can i acheive this? Please help here

Thank you

Regards
Sainath.
 
Best Answer chosen by sainath chalamcherla 9
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sainath,

It worked for me. I tried some code as below and it created lead.
 
global class LeadEmailHandler implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    
    String body = email.plainTextBody;
    String[] differentsections = body.split('\n');
      system.debug('lines'+differentsections);
    String firstName;
    String lastName;
    String phone;
    String emailAddr;
    Date dob;
    String leadId;
    for (String line : differentsections) {
      if (line.startsWith('Customer Name')) {
        String[] nameParts = line.split(':');
        if (nameParts.size() > 1) {
          String[] fullName = nameParts[1].trim().split(' ');
          if (fullName.size() > 1) {
            firstName = fullName[0];
            lastName = fullName[1];
          }
        }
      } else if (line.startsWith('Email address')) {
        String[] emailParts = line.split(':');
        if (emailParts.size() > 1) {
          emailAddr = emailParts[1].trim();
        }
      } else if (line.startsWith('Phone number')) {
        String[] phoneParts = line.split(':');
        if (phoneParts.size() > 1) {
          phone = phoneParts[1].trim();
        }
      } else if (line.startsWith('Date of birth')) {
        String[] dobParts = line.split(':');
        if (dobParts.size() > 1) {
          String dobStr = dobParts[1].trim();
          dob = Date.valueOf(dobStr);
        }
      } 
    }
    system.debug('asas'+lastName);
    Lead newLead = new Lead();
    newLead.FirstName = firstName;
    newLead.LastName = lastName;
    newLead.Phone = phone;
    newLead.Email = emailAddr;
      newLead.Company='sample';
    //newLead.Birthdate = dob;
    insert newLead;
    
    result.success = true;
    return result;
  }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Do they give enter after every detail. If so you can try body.split('\n') and add it to some List and use it 

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
 
sainath chalamcherla 9sainath chalamcherla 9
Sai Praveen, It doesn't works 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sainath,

It worked for me. I tried some code as below and it created lead.
 
global class LeadEmailHandler implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    
    String body = email.plainTextBody;
    String[] differentsections = body.split('\n');
      system.debug('lines'+differentsections);
    String firstName;
    String lastName;
    String phone;
    String emailAddr;
    Date dob;
    String leadId;
    for (String line : differentsections) {
      if (line.startsWith('Customer Name')) {
        String[] nameParts = line.split(':');
        if (nameParts.size() > 1) {
          String[] fullName = nameParts[1].trim().split(' ');
          if (fullName.size() > 1) {
            firstName = fullName[0];
            lastName = fullName[1];
          }
        }
      } else if (line.startsWith('Email address')) {
        String[] emailParts = line.split(':');
        if (emailParts.size() > 1) {
          emailAddr = emailParts[1].trim();
        }
      } else if (line.startsWith('Phone number')) {
        String[] phoneParts = line.split(':');
        if (phoneParts.size() > 1) {
          phone = phoneParts[1].trim();
        }
      } else if (line.startsWith('Date of birth')) {
        String[] dobParts = line.split(':');
        if (dobParts.size() > 1) {
          String dobStr = dobParts[1].trim();
          dob = Date.valueOf(dobStr);
        }
      } 
    }
    system.debug('asas'+lastName);
    Lead newLead = new Lead();
    newLead.FirstName = firstName;
    newLead.LastName = lastName;
    newLead.Phone = phone;
    newLead.Email = emailAddr;
      newLead.Company='sample';
    //newLead.Birthdate = dob;
    insert newLead;
    
    result.success = true;
    return result;
  }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Linda EwingLinda Ewing
This means that you should download the PikaShow Modified APK version (https://www.pikashowhd.com/pikashow-mod-apk-fhk/) from our website if you want to escape the app's official membership plans. Notably, our links are 100 percent private and work with the best iPhone models, Android phones, and Windows-based gadgets.
tier ktier k
This is the best place to get mod app updates. I have known many app related solution on this page. Everything fine and good but here, I brought you about one thing that is Pikashow app. It is one of the best app to provide an entertainment. So, you may have a look on this guide, how to install Pikashow for iOS. Really, you will enjoy more on this app. In addition to this, if you are tired and not able to downloaded Pikashow on PC? then, here is the perfect guide get the app on your Windows and enjoy it.
VIKKI KING 6VIKKI KING 6
if you are looking for free entertainment for your android phone pikashow apk download (http://pikashowapkdownloads.com) provide you fre entertsainment to get more views.
Michael Wik 4Michael Wik 4
Kepala Bergetar (https://kepalabergetarwatch.com/)is best another entertainment source that you can avail in free. If you want to get access to all entertainment content then this best website which is Kepala Bergetar (https://kepalabergetarhd.live/)that you should follow to  get entertainment.
Smith EarnestSmith Earnest
CapCut is indeed an app, specifically a video editing app developed by ByteDance, the same company behind TikTok. CapCut is available (https://capcutpc.pro/) for both Android and iOS devices, allowing users to edit videos easily and quickly on their smartphones or tablets. With its user-friendly interface and a wide range of editing features, CapCut has gained popularity among content creators and video enthusiasts looking for a convenient and accessible video editing solution.
Michael Wik1Michael Wik1
GPT-4, der neueste Algorithmus aus der GPT-Reihe von OpenAI’s großen Sprachmodellen, bietet bedeutende Fortschritte im Vergleich zu seinem Vorgänger, GPT 3.5, der ChatGPT 4 (https://chatgptlogins.com/chat-gpt-4/) antreibt.  
Willkommen bei Chat GPT Deutsch (https://chatgptdeutschai.de/)! Chat GPT steht für „Generative Pre-trained Transformer“ und ist eine fortschrittliche KI-Technologie, die mithilfe von natürlicher Sprache realistische Gespräche führen kann.
mohammed kalimullmohammed kalimull
Welcome to PikaShow apk download (http://piikashowapk.com/), your ultimate destination for downloading the most recent and past APK versions of the PikaShow App, all of which are completely secure and protected against bans. In addition, we offer comprehensive information about PikaShow (http://piikashowapk.com/), ensuring our users have the best possible experience. 
Abdullah Sahi 8Abdullah Sahi 8
The benefits of Vedu App (https://veduapk.co/) aren't limited to traditional schooling; it also supports continuous learning and professional development.
  1. Pikashow (https://pikashowapp.fun/)
  2. Hunk TV APK (https://hunktv.ltd/)
  3. https://pikashowapp.fun/
asna daskasna dask

you can download pikashow latest version from here:::::

https://pikashowapp.org/ (https://pikashowsapks.me/)

https://pikashowsapks.me/

Bangalore Escorts 11Bangalore Escorts 11
Nice article keep it up like this in your future.I hope you do best afford and make future bright.
Bangalore Escorts
 
Bangalore Escorts 13Bangalore Escorts 13
Thank you for this information.
This blog post is very helpful or needed for the future posts.
Escorts In Bangalore
Mumbai EscortsMumbai Escorts
Great post thank you.
By: Mumbai Escorts Service
 
Chat GPT LoginChat GPT Login
If you are a blogger and looking to create blogposts within seconds then use Chat GPT (https://chatgptlogn.com/) for quick post.
Shannu KhanShannu Khan
Picasso App (https://picassoappbox.com/)is a fantastic online streaming platform where you can watch Sports matches, Movies, TV Shows, Web Series, Documentaries, and News
Shannu KhanShannu Khan
One of the best things about Kinemaster mod apk (https://kinemastermodapk.blog/)is how simple it is
asna daskasna dask
Your content is very good and useful to me check also: https://lightroomapk.net/
asna daskasna dask
thanks for sharing it you may check https://instapro2apk.com/ from here.
Ashu Patel 2Ashu Patel 2
You should definitely learn about the Picasso app and the Picasso App Download (https://picassoappdownload.tech/" target="_self) on any Android device.
pinoy flix 16pinoy flix 16
pinoy flix channel is one of the best where Filipino can Enjoy Pinoy Teleserye, PinoyFlix, Pinoy Tambayan Shows from work, after a busy schedule, and the workplace. https://pinoyflix.com.co/
antenia antenia 1antenia antenia 1
For more guides visit here (http://hillclimbracingapk.net/).
Spotiflyer OnlineSpotiflyer Online
SpotiFlyer APK is a simple offline music programme that allows you to listen to music whenever and wherever you want, even when you aren’t connected to the Internet. An offline music programme that allows you to listen to your favourite songs without having to be online with Spotiflyer (https://spotiflyeronline.com/)!
Chennai BeautiesChennai Beauties
I really like your post, because all the information posted in this article is very Impressive. Suppose you are looking for hot and sexy call girls in Chennai. You may visit my excellent profile by clicking here. Independent Chennai escorts
 
maya roymaya roy
Our Gurgaon Russian Escorts (https://yashasavikhanna.com) consider an air where you can loosen up erotic administrations, proposed to facilitate your collection of regular pressures. Our young ladies can spoil you with a delicate touch Escorts Service Beirut and besides continue further and facilitate your pressure.
Martin PeterzMartin Peterz
This can easily be done. You just need to research more related to SMPTs in Apache based servers. While the Pikashow APK for Mobile (https://pikashowpc.com/pikashow-apk-download/) is also using the same technique and targetting their paid customers.
blink appblink app
Users may operate a variety of Geeni App (https://geeniforpc.web.app/)smart devices using the Geeni app, which is a flexible smart home management hub. The Geeni software was first created for mobile devices, but it has since developed to be compatible with PCs(https://geeniforpc.web.app/) increasing its accessibility and usefulness for users who want a computer's bigger screen and other features.
Mona KhanMona Khan
I truly intriguing the manner in which you featured some vital focuses. Much appreciated without a doubt
From :-  https://www.hyderabadbeauties.com
Snaptube AppSnaptube App
Snaptube (https://snaptubeapps.net/)YouTube downloader & MP3 converter is a simple tool to download any video from 
YouTube and many other similar services in an easy, fast streaming app for music and app
Download the latest version of Snaptube YouTube downloader & MP3 converter for Android. 
 
cinema hd firestickcinema hd firestick
Cinema HD is the easiest way to browse through your favorite movies. We present this Cinema for free
Cinema HD (https://cinemahdappapk.net/ )is a great app for your Android devices that gives you a list of popular movies, TV shows.
 
YT MP3YT MP3
Convert YouTube videos to mp3 music files for free with the YtMP3 web app online free.
YouTube to Mp3 Music Converter Convert Youtube to mp3 online for official website in hd.

YTMP3 (https://ytmp3.pub/)