• Daniel Johnson 8
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hi All,
I am attempting to create an email service that creates a lead and processes the information within the body of the email. I have been getting errors for a few days now so I figured its time to ask the community. Below is the code...Thanks in advance!!



global class PurchasedLeads implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){
 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    String emailBody = email.plainTextBody;
    String companyName = emailbody.Substring(emailbody.IndexOf('Website Entered On:') + 20, emailbody.IndexOf('Practice Area:') - emailbody.IndexOf('Website Entered On:')-20);
    String firstName = emailbody.Substring(emailbody.IndexOf('First Name:') + 12, emailbody.IndexOf('Last Name:') - emailbody.IndexOf('First Name:')-12);
    String lastName = emailbody.Substring(emailbody.IndexOf('Last Name:') + 11, emailbody.IndexOf('Email:') - emailbody.IndexOf('Last Name:')-11);
    String emailAddress = emailbody.Substring(emailbody.IndexOf('Email:') + 7, emailbody.IndexOf('Phone Number:') - emailbody.IndexOf('Email:') - 7);
    String phoneNumber = emailbody.Substring(emailbody.IndexOf('Phone Number:') + 14, emailbody.IndexOf('Request Details') - emailbody.IndexOf('Phone Number:') - 14);

    Lead[] newLead = new Lead[0];
     try {
       Map<String, Schema.SObjectType> sObjectMap = Schema.getGlobalDescribe() ;
       Schema.SObjectType s = sObjectMap.get('Lead') ;
       Schema.DescribeSObjectResult resSchema = s.getDescribe() ;

     newLead.add(new Lead(Company = companyName, LastName = lastName, Email = emailAddress,Phone = phoneNumber));
       insert newLead; 
            
    }
    
   catch (QueryException e) {
       
   }
   
   result.success = true;
   return result;
  }
}
Hi All,
I am attempting to create an email service that creates a lead and processes the information within the body of the email. I have been getting errors for a few days now so I figured its time to ask the community. Below is the code...Thanks in advance!!



global class PurchasedLeads implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){
 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    String emailBody = email.plainTextBody;
    String companyName = emailbody.Substring(emailbody.IndexOf('Website Entered On:') + 20, emailbody.IndexOf('Practice Area:') - emailbody.IndexOf('Website Entered On:')-20);
    String firstName = emailbody.Substring(emailbody.IndexOf('First Name:') + 12, emailbody.IndexOf('Last Name:') - emailbody.IndexOf('First Name:')-12);
    String lastName = emailbody.Substring(emailbody.IndexOf('Last Name:') + 11, emailbody.IndexOf('Email:') - emailbody.IndexOf('Last Name:')-11);
    String emailAddress = emailbody.Substring(emailbody.IndexOf('Email:') + 7, emailbody.IndexOf('Phone Number:') - emailbody.IndexOf('Email:') - 7);
    String phoneNumber = emailbody.Substring(emailbody.IndexOf('Phone Number:') + 14, emailbody.IndexOf('Request Details') - emailbody.IndexOf('Phone Number:') - 14);

    Lead[] newLead = new Lead[0];
     try {
       Map<String, Schema.SObjectType> sObjectMap = Schema.getGlobalDescribe() ;
       Schema.SObjectType s = sObjectMap.get('Lead') ;
       Schema.DescribeSObjectResult resSchema = s.getDescribe() ;

     newLead.add(new Lead(Company = companyName, LastName = lastName, Email = emailAddress,Phone = phoneNumber));
       insert newLead; 
            
    }
    
   catch (QueryException e) {
       
   }
   
   result.success = true;
   return result;
  }
}