function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Visualforce Email Template referring Opportunity line item fields


I need to create a VF email template in Salesforce and need to refer opportunity line items. I have custom object training__C that has a lookup with Opportunity object.

How can I refer Opportunity line items from training__C object?

Thanks for your help.
SonamSonam (Salesforce Developers) 

I tried this on my org and turns out that accessing the opportunity line item from the custom object will not be possible as this would need a controller to access the line items on the page and as a template cannot call a controller - this would be difficult to acheive.

A workaround to this is to wite a custom component which works with a controller to get opportunity line items and then call this component in your visualforce template.

The below thread talks about it with sample code: