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 to generate 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 attempting to use this attribute on one used for other purposes.

Tip

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 attaching the PDF generated to records for 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. Translation and localization Chapter 2, Leveraging Platform Features, covered this topic, 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 afterwards.

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.

Tip

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.

Overriding the page language

By default, the Visualforce page looks up translated text for Custom Field labels and Custom labels that you reference on your page or in your Apex code through the user's locale. However, if you wish to override this, you can specify the <apex:page> language attribute, for example, if you wish to use a Visualforce page to generate a newsletter in different languages and wish to preview them before sending them out.

Note

There is no equivalent functionality for Lightning Components; these always leverage the language of the user.

This does not apply to any descriptive field values such as Name or any custom description fields that you add to your objects. In order to provide translation for the data entered by a user, you must develop such a feature yourself. There is no platform support for this.

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

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