You need to sign in to do that
Don't have an account?
TN Admin
How to get the opportunity product fields in visualforce email template?
How to get the opportunity product fields in visualforce email template?
I have created VF email template relatedTo Contract__C object
Relationship:
Opportunity object---Lookup--->Contract__C object
Now hot to get the opportunity products fields on VF email template?..
I have created VF email template relatedTo Contract__C object
Relationship:
Opportunity object---Lookup--->Contract__C object
Now hot to get the opportunity products fields on VF email template?..
Hello,
In this scenario, you can use controller with email template. Following are the steps you have to follow to achieve this functionality:
1. Create Visualforce component with controller
2. Write Apex repeat logic in your visualforce component (Display Opportunity Products)
3. Create Email template and use visualforce component in your email template with following tag:
4. You can access this ID in your controller with following tag:
5. Here oppId is a get set variable, you can use this to Query on Opportunity Line Items to fetch all products and can use those product list in Apex repeat.
I hope it helps you to acheive your requirement. I am not sending you to full code, because I want you to first try it your self.
Please mark this as best answer, if it helps you, so that this solution would be easily searchable by other users.
Thanks,
Yogesh Sharma
All Answers
Hello,
As per my understanding you have following relations:
1. Parent object: Contract__c
2. Child: Opportunity
And you want to fetch Opportunity product in your visualforce email template. If requirement is the same, then you cannot fetch Opportunity Line Item in visualfore page email template by using Apex repeat. Because Opportunity Line Item is a sub-child of Contract__c and you cannot traverse more than 1 level in aggregate function.
Solutions:
To achieve this functionality, you have to use controller with visualforce Email template. Create a visualforce component with Controller and use that component in your visualforce email tyemplate. From Visualforce email template, you can pass Contract__C ID to component controller to fetch all Opportunities and related products.
I hope it helps you to achieve this functionality.
Please mark this answer as best if it helps you, so that it will be easy to search for other users.
Thanks,
Yogesh Sharma
Child: Contract__C
can you please help me how the code look like for both email template and controller...
Thanks in advance....
Hello,
In this scenario, you can use controller with email template. Following are the steps you have to follow to achieve this functionality:
1. Create Visualforce component with controller
2. Write Apex repeat logic in your visualforce component (Display Opportunity Products)
3. Create Email template and use visualforce component in your email template with following tag:
4. You can access this ID in your controller with following tag:
5. Here oppId is a get set variable, you can use this to Query on Opportunity Line Items to fetch all products and can use those product list in Apex repeat.
I hope it helps you to acheive your requirement. I am not sending you to full code, because I want you to first try it your self.
Please mark this as best answer, if it helps you, so that this solution would be easily searchable by other users.
Thanks,
Yogesh Sharma
No. You have to write controller for this.
Thanks,
Yogesh Sharma