Have you ever wanted to send an email from an opportunity in Salesforce with a list of the product line items? Maybe you need a workflow that notifies Finance of the products sold when an opportunity hits the stage of closed/won? Or how about an automated email with the list of products sold sent to the person who most needs to see this information?
I have seen Salesforce Administrators struggle with these types of requests for years. Fortunately now with Visualforce email templates you can do any of the above and more. Visualforce email templates allow you to use Apex code to pull related information as well as information from the detail record with some minor programming and HTML skills.
If you are a Salesforce drag and drop user, you may be hesitant to jump into Visualforce templates. But as it turns out, Salesforce Labs has a great solution for you. They have a free app on the AppExchange called “Product Line Items in Email Templates” that has sample templates with the Apex code already developed.
This is a great time saver! Just install “Product Line Items in Email Templates” and then clone the sample. You can then modify the HTML code, merged fields, and layout to meet your needs. By using the “Send Test and Verify Merge Fields” button, you can see the results of your modifications as you make them. This can simplify your Salesforce development process.
Apex code may seem a little frightening at first but like anything new once you start to understand the basics, it starts to fall into place. This little app can help you to get started with Apex code and create Visualforce email templates at the same time.
Salesforce’s versatility increases dramatically when you add Apex and Visualforce capabilities. For those of you that have been hesitant to try Visualforce or Apex, this is a great place to start.
StarrForce is a Salesforce Partner that helps companies deploy, optimize and support Salesforce.com. If you would like information on the services we offer call us at (888) 391-4493 Ext. 101.
I created a visual force template for one of my custom objects (Master Detail relation) but it’s not fully operational. The problem is I have a workflow rule set up for the master object which kicks off the email before the line items are inserted. The visual force email template neither throws any error nor show the details. But, if i modify some existing record then it works just fine. Any suggestions?
Since the workflow is sending the email before the line items are inserted, you may want to look at different criteria or an Apex trigger. Below is the order that rules and triggers fire from Salesforce help:
Knowledge Article Number: 104371
Description
In what order are automation rules and Apex triggers processed?
Resolution
The following is the order salesforce logic is applied to a record.
Old record loaded from database (or initialized for new inserts)
New record values overwrite old values
System Validation Rules
All Apex before triggers (EE / UE only)
Custom Validation Rules
Record saved to database (but not committed)
Record reloaded from database
All Apex after triggers (EE / UE only)
Assignment rules
Auto-response rules
Workflow rules
Escalation rules
Parent Rollup Summary Formula value updated (if present)
Database commit
Post-commit logic (sending email)
Additional notes:
There is no way to control the order of execution within each group above.
Workflow field updates that run based on an approval process or time-dependent action do not trigger any rules.
Formula fields do not execute in this way. They calculate and display their results real-time whenever the field is accessed in any way. So for example if a Workflow Rule uses a Formula Field in its criteria or formula, the formula field is evaluated when the Workflow Rule criteria is checked.
Hope this helps,
Admin