Generating printable content

Salesforce has a built-in PDF generation engine that can take your HTML markup and turn it into a PDF. This is a very useful feature for generating more formal documents such as invoices or purchase orders.

You can access it using the renderAs attribute of the apex:page element on a Visualforce page, setting it to pdf. Note that you would typically dedicate a specific Visualforce page for this purpose rather than attempt to use this attribute on one that's used for other purposes.

Make sure that you use as much vanilla HTML and CSS as possible; the Visualforce standard components do not always render well in this mode. For this reason, it is also useful to use the standardStylesheets attribute to disable Salesforce CSS as well.

You can also programmatically access this capability by using the PageReference.getContentAsPDF method and attach the PDF generated to records for the future. If you would rather generate PDF content without using a Visualforce page, you can generate the HTML programmatically and leverage the Blob.toPDF method. In Chapter 2, Leveraging Platform Features, we covered translation and localization, so we will not be revisiting it in further detail here. Just to reiterate, it is important to consider translation and localization requirements from the outset, as they can be expensive to retrofit afterward.

Also, note that in the preceding example, the $ObjectType global variable was used in the Visualforce page to access the Custom Field label for the column title. Ensuring that you leverage approaches like this will reduce the number of Custom Labels you need to create and, ultimately, your translation costs.

Lightning Components do not currently support $ObjectType; as a workaround, you can use Apex Describe to expose this via your Apex Controller.

In Visualforce, you can use the apex:inputField and apex:outputField components to render and receive input from the user, which is locale sensitive. In Lightning, utilize the lightning:formattedNumber and lightning:formattedDateTime components.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.175