2

I have an email template that contains a custom component with code:

<messaging:emailTemplate subject="Your Recent Order" recipientType="Contact" relatedToType="Order">
<messaging:htmlEmailBody >
    <c:MyCustomComponent />
</messaging:htmlEmailBody>

The email template works fine, however when navigating to: Communication Templates > Email Templates and then clicking on the specific email template name, I am brought to the email template detail page. However, there is the following error that appears at the top of the page:

Attempt to dereference null object

If I comment out the the element in the email template the error goes away. So, it appears that the error has something to do with the inclusion of the custom component. Anyone know why this may be occurring?

1 Answer 1

1

Ah yes, this problem most likely occurs because the controller used by MyCustomComponent is getting a reference to a null object.

Such controller needs to be extra careful about testing for null objects -- because when invoked in the email template detail, the normal context you might expect when used in a transaction does not exist.

To resolve this, test your custom component using anonymous Apex and you should be able to see where the null reference occurs (line number).

3
  • This is pretty common for components to error out in the email template detail. Try previewing the email template and as long as the error isn't occurring there you should be good. Typically the component is expecting an Id of some form which isn't supplied in the email template detail page. Jul 7, 2014 at 22:10
  • 1
    @Ralph -- yes, you are correct - the preview will be accurate. But I remember just hating to see that error icon and went into my controller and ensured it would not NPE even if no id was supplied.
    – cropredy
    Jul 7, 2014 at 22:34
  • Thank you crop1645. You are indeed correct. As Ralph stated, I can preview the email template fine, however, it's the annoying error at the top that I was trying to get rid of. Jul 8, 2014 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .