Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a email service to receive a emil from a provided email id I want to print the emiail body in debug log for this I write some debug to that but my problem is nothing get printes in debug log so will you please suggest me how to print email body in debug log.

My email service class code -

global class ProcessCaseEmail implements Messaging.InboundEmailHandler
    ProcessCaseEmail ()

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

        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String myPlainText= '';
        myPlainText = email.plainTextBody;
        System.debug('Plain text+++++++++++' + myPlainText );
        List<String> parts = myPlainText.split('\n');

        List<String> columns;
        for(integer i=0;i<parts.size();i++)

            System.debug('Parts+++++     ['+i+']   '+parts[i] );
            system.debug('Length of the parts ['+i+']  '+parts[i].length());

        return result;
share|improve this question
Have you turned on debug logging for the context user of the email service? – Bob Buzzard Jan 16 '13 at 8:20
can you please elaborate more. – D-Horse Jan 16 '13 at 11:16
The answer below covers this. – Bob Buzzard Jan 16 '13 at 11:25

You are only printing the plain text body, perhaps you are sending your email as HTML?

this works perfectly for me:

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

        System.debug('HTML BODY: '+email.htmlBody);
        System.debug('TEXT BODY: '+email.plainTextBody);
        System.debug('SUBJECT: '+email.subject);

        return result;

Do make sure you put on debug logging for it to work, go to:

  • Setup
  • Administration Setup
  • Montitoring
  • Debug Logs
  • Add a New monitored user (make sure you choose the user you setup for handling your inbound email)

Send your mail, refresh the page, there should now be logs available:

Log Overview Log

share|improve this answer

Or if you are the context user - you can just monitor the logs in the Developer Console as they occur.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.