+ Start a Discussion
withoutmewithoutme 

test method for email headers in apex email services

How do I specify the name,value for email headers in my test method for inbound email services?

Messaging.InboundEmail.Header[] hd = email.headers[name='Date', value='Tue, 28 Apr 2009 14:08:37 -0700']; THIS GIVES AN ERROR Messaging.InboundEmail.Header[] hd = email.headers; hd[0].name='Date'; hd[0].value='Tue, 28 Apr 2009 14:08:37 -0700']; THIS GIVES SYSTEM.NULLPOINTEREXCEPTION ERROR

 Any help will be greatly appreciated

Best Answer chosen by Admin (Salesforce Developers) 
Rasmus MenckeRasmus Mencke

You can use this to test the headers of an inbound email:

 

 

Messaging.InboundEmail.Header hditem= new Messaging.InboundEmail.Header(); email.headers=new Messaging.InboundEmail.Header[1]; hditem.name='Date'; hditem.value='Tue, 28 Apr 2009 14:08:37 -0700'; email.headers[0]=hditem;

 

 

 

All Answers

JimRaeJimRae

There is a great sample here that should help you LINK

 

http://wiki.developerforce.com/index.php/Code_Sample_-_Testing_Email_Services_with_Inbound_Attachments

Rasmus MenckeRasmus Mencke

You can use this to test the headers of an inbound email:

 

 

Messaging.InboundEmail.Header hditem= new Messaging.InboundEmail.Header(); email.headers=new Messaging.InboundEmail.Header[1]; hditem.name='Date'; hditem.value='Tue, 28 Apr 2009 14:08:37 -0700'; email.headers[0]=hditem;

 

 

 

This was selected as the best answer
withoutmewithoutme
Thank you. I did the same thing and it worked.