You need to sign in to do that
Don't have an account?

VisualForce Component in VisualForce Email Template De-referencing Null Object?
Hi there, beginner VF/Apex coder here.
I have a VF email template where the relatedTo object is Asset. I would like to add a VF component that displays a table of all the sibling assets under the same account. Here is my code so far:
Constructor:
And here are relevant parts of the email template:
However, after I save the Email Template page, or try to to a test merge, I get the message: "Error occurred trying to load the template for preview: Attempt to de-reference a null object. Please try editing your markup to correct the problem."
I cannot figure out for the life of me what I'm doing wrong! Please help!
I have a VF email template where the relatedTo object is Asset. I would like to add a VF component that displays a table of all the sibling assets under the same account. Here is my code so far:
Constructor:
public class findSiblingAssets { private final List<Asset> assets; public Asset ast {get; set;} public findSiblingAssets() { assets = [select Id, AccountId, Name, UsageEndDate from Asset where AccountId = :ast.AccountId]; } public List<Asset> getSiblingAssets() { return assets; } }Component (Named "FindSiblingAssets"):
<apex:component controller="findSiblingAssets" access="global"> <apex:attribute type="Asset" name="originast" assignTo="{!ast}"/> <apex:dataTable value="{!SiblingAssets}" var="sib"> <apex:column > <apex:facet name="header">Asset Name</apex:facet> {!sib.Name} </apex:column> </apex:dataTable> </apex:component>
And here are relevant parts of the email template:
<messaging:emailTemplate relatedToType="Asset" subject="Subject Line here" replyTo="replyaddress@email.com"> <messaging:htmlEmailBody > <html> ... <c:FindSiblingAssets originast="{!relatedTo}"/> ... </html> </messaging:htmlEmailBody> </messaging:emailTemplate>
However, after I save the Email Template page, or try to to a test merge, I get the message: "Error occurred trying to load the template for preview: Attempt to de-reference a null object. Please try editing your markup to correct the problem."
I cannot figure out for the life of me what I'm doing wrong! Please help!
This happens since you are passing in an object (originast="{!relatedTo}"), which will be null in the preview.
I would not worry, unless you have specific reason to see the preview in the email template.
To expose a preview to the end user, I had used the component in a VF page where in I would pass the 'originast="{!relatedTo}"' from the VF controller.
I did modify the code so that rather than passing the Asset, it should now just pass the {!relatedTo.AccountId} String of the asset. However, it seems that this value is not making it to the controller; (if I remove the "where" criteria, the table displays correctly, however otherwise, no rows are returned.)
Here is the updated code, please help!
Controller: VF Component: VF email template component call:
Did anyone find solution for this? I am also facing same issue.Somehow {!related.AccountId} is not reaching to VF Component controller, where clause with static value, returning back result.
Please help if anyone came across this issue. Your help really appreachiated.