You need to sign in to do that
Don't have an account?
CMcCaul
System.NullPointerException: Attempt to de-reference a null object
Class.EmailToCase.handleInboundEmail: line 22, column 5
null email.plainTextBody
I have the following code in my email to case class:
global class EmailToCase implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult
handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
// Create an inboundEmailResult object for returning the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
global Messaging.InboundEmailResult
handleInboundEmail(Messaging.inboundEmail email,
Messaging.InboundEnvelope env){
// Create an inboundEmailResult object for returning the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
system.debug('\n\nTo: ' + email.toaddresses[0] + '\nFrom: ' + email.fromaddress + '\nSubject: ' + email.subject + '\nBody: ' + email.plainTextBody + '\n');
// remove confidentiality notices from email body
if (email.plainTextBody.contains('CONFIDENTIALITY NOTICE:')) {
i = email.plainTextBody.indexOf('CONFIDENTIALITY NOTICE:');
email.plainTextBody = email.plainTextBody.substring(0,i-1);
}
if (email.plainTextBody.contains('CONFIDENTIALITY NOTICE:')) {
i = email.plainTextBody.indexOf('CONFIDENTIALITY NOTICE:');
email.plainTextBody = email.plainTextBody.substring(0,i-1);
}
and this afternoon I have started to get this error in my debug log:
To: xxxx@xxxx.com
From: xxxx@xxx.com
Subject: xxxxxxxx
Body: null
System.NullPointerException: Attempt to de-reference a null object
Class.EmailToCase.handleInboundEmail: line 22, column 5
Line 22, column 5 is trying to reference email.plainTextBody for the first time (.contains). This has been working for a few weeks. Has something changed at Salesforce with the inbound email, or do I need to code for some e-mails to actually have a null email.plainTextBody? The e-mails I received from our mail server do in fact have a body with normal text and a confidentiality notice. Any ideas?
Thanks
Matches any HTML tag with any parameters. Very useful to clean HTML of a text
http://regexlib.com/REDetails.aspx?regexp_id=1895
Pattern htmlPattern = Pattern.compile('</?[a-z][a-z0-9]*[^<>]*>'); String contentWithoutHTML= htmlPattern.matcher('<html><body><p>Test 16h37</body></html>').replaceAll(''); System.debug('### Result:'+contentWithoutHTML);