I have the following in an email template, which works:
<!-- template item display name -->
<apex:outputText rendered="{!NOT(ISBLANK(relatedTo.Template_Item_Displayname__c)) && NOT(kit)}"
value="{!$Label.Localized_Product_Description + ': ' + relatedTo.Template_Item_Displayname__c}" />
<c:NewLine rendered="{!NOT(ISBLANK(relatedTo.Template_Item_Displayname__c)) && NOT(kit)}" />
<apex:outputText rendered="{!NOT(ISBLANK(relatedTo.Parent_Serial__r.Template_Item_Displayname__c)) && kit}"
value="{!$Label.Localized_Product_Description + ': ' + relatedTo.Parent_Serial__r.Template_Item_Displayname__c}" />
<c:NewLine rendered="{!NOT(ISBLANK(relatedTo.Parent_Serial__r.Template_Item_Displayname__c)) && kit}" />
If I remove the last two parts, it errors:
<!-- template item display name -->
<apex:outputText rendered="{!NOT(ISBLANK(relatedTo.Template_Item_Displayname__c)) && NOT(kit)}"
value="{!$Label.Localized_Product_Description + ': ' + relatedTo.Template_Item_Displayname__c}" />
<c:NewLine rendered="{!NOT(ISBLANK(relatedTo.Template_Item_Displayname__c)) && NOT(kit)}" />
Error:
Error occurred trying to load the template for sending preview email: SObject row was retrieved via SOQL without querying the requested field: Serial_Number__c.Template_Item_Displayname__c. Please try editing your markup to correct the problem.
Here is the SOQL:
SELECT
contact.Email,
contact.Language_Code__c,
contact.Name,
license.Activation_Code__c,
license.Entity_Id__c,
license.Topcon_One_Created_By__r.Name,
psn.Item_Number__r.Id,
psn.Item_Number__r.Display_Name__c,
psn.Dealer_Purchase_Order__c,
psn.Email_Notification_Contacts__c,
psn.Item_Description__c,
psn.Name,
psn.Product_Family__c,
psn.Team__r.Name,
psn.Template_Item_Displayname__c,
psn.Template_Item_Number__c,
psn.Topcon_Sales_Order__c,
psn.Id,
sn.Dealer_Purchase_Order__c,
sn.Email_Notification_Contacts__c,
sn.Item_Description__c,
sn.Name,
sn.Product_Family__c,
sn.Team__r.Name,
sn.Template_Item_Displayname__c,
sn.Template_Item_Number__c,
sn.Topcon_Sales_Order__c,
Id // last for easy sorting
FROM
License_Activation__c license,
license.Serial_Number__r sn,
sn.Parent_Serial__r psn,
sn.End_User_Contact__r contact
WHERE Id IN :activationIds
I'm not sure how removing something would cause this error?