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
Benjamin HimleyBenjamin Himley 

Email-to-Lead service Apex question

I'm trying to set up an email-to-lead email service where the information for the lead is in the content of the email iteself.
The leads always come from the same email to my Outlook email.  The email contains the information for the lead in its content.  I have set up an apex class, and an email service within Salesforce, and have activated the email service.  I set up a rule within outlook to automatically redirect emails to the salesforce email given in the email service. 
No new leads are bein created at all, however.  I can't figure out why.  Are there logs of some kind I could check?  In the email service I have Email Error Routing enabled, and have it set so that it sends errors to my email, but I haven't received any error emails from salesforce (although I have been having issues with receiving emails from salesforce ip's, so they might actually be getting sent).  Here is my Apex class:

global class NmsEmailToLead implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,

                                                       Messaging.InboundEnvelope env){


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

    String[] emailBody = email.plainTextBody.split('\n', 0);

    String firstName = emailBody[1].substring(10);
    
    String lastName = emailBody[2].substring(10);

    String address = emailBody[3].substring(8);

    String state = emailBody[4].substring(5);

    String zipcode = emailBody[5].substring(7);

    String city = emailBody[6].substring(4);

    String leadEmail = emailBody[7].substring(12);

    String phone = emailBody[8].substring(8);

    String paymentsBehind = emailBody[11].substring(15);

    String loanAmount = emailBody[13].substring(11);

    String estimatedHomeValue = emailBody[14].substring(21);

    String creditLevel = emailBody[17].substring(12);

    String interestRate = emailBody[20].substring(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() ;
        Map<String,Schema.RecordTypeInfo> recordTypeInfo = resSchema.getRecordTypeInfosByName();
        Id rtId = recordTypeInfo.get('Housing Counseling').getRecordTypeId();

       newLead.add(new Lead(RecordTypeId = rtId,
       FirstName=firstName,LastName=lastName,Phone = phone,Email = leadEmail,
       Street = address,State = state,City = city,PostalCode = zipcode,
       Payments_Behind__c = decimal.valueof(paymentsBehind),Total_Amount__c = decimal.valueof(loanAmount),
       Estimated_Home_Value__c = decimal.valueof(estimatedHomeValue),
       Credit_Level__c = creditLevel,Interest_Rate__c = decimal.valueof(interestRate)));

       insert newLead;       
    }
     
   catch (QueryException e) {
        
   }
    

   result.success = true;

   return result;

  }

}

Any help with understanding what I am doing wrong here would be greatly appreciated, thanks!
SonamSonam (Salesforce Developers) 
Did you try sending an email directly to the email service you have created instead of it routing via the outlook?

You can also try  the following way of troubleshooting the issue related email services:
https://help.salesforce.com/HTViewHelpDoc?id=inbound_email_snapshots.htm&language=en_US
Ariel GorfinkelAriel Gorfinkel
Although this is probably not relevant now after two years, but maybe for future refeneces.
An error email won't be sent unless the InboundEmailResult "success" is set to false.
catch (Exception e) {
    result.success = false;
    result.message = e.getMessage();
}