Recently, the license for one of the apps we use to generate documents in PDF format expired. And as expected, the service provider raised the subscription price for renewal, so I decided to ‘get rid of’ them and build our own custom solution. (Pretty standard as an ops engineer hey?)
The main purpose of us having this app is to ship an invoice to our partners when certain actions happen (workflow). Our partners will receive emails with a pdf file attached.
I thought it would be super easy to set up a visualforce page and simply set the following to render the page as a PDF file:
However, I was wrong, all stylings in the visualforce page are dismissed when salesforce converts it to PDF, the resulting file looks like an image taken in 1880s…
After few attempts, I got the solution to work. The final product is simply a visualforce page running on a salesforce sites (so users, our partners, don’t need licenses to access files), and on the bottom of the page, I place a print button like so.
<input type="button" value="Print" onclick="window.print()" />
Here is the flow:
- Whatever actions trigger emails to partners;
- Within the email, there is a link similar to xxx.force.com?id= that opens the ‘record’ on a salesforce site with a desired layout;
- Users open the link and review the page and print or save to local storage if needed.
This challenge shows how we can leverage salesforce sites and other technologies outside of salesfore to achieve business needs with a minimum cost.