Loading

Develop code to open PDF with Salesforce for Android and iOS app

Udgivelsesdato: Apr 30, 2025
Beskrivelse

It's possible to open a PDF view in the Salesforce for Android and iOS app. The PDF shows up as a thumbnail view, and there is a download link where a full view can be accessed in another browser window. However there are some best practices to follow, as well as known limitations to be aware of, which will be outlined here.

Best Practices

Use the sforce.one.navigateToSObject() event call to open the PDF in the mobile app environment. This method call is meant to be used in the Salesforce for Android and iOS app environment only. We do not recommend hard coding URL values to open the PDF in the Salesforce for Android and iOS app. The navigateToSObject() event call is the recommended way to render a PDF view from the Salesforce for Android and iOS app.

NOTE: The navigateToSObject() event call opens the PDF in a new browser window on the mobile device. This is working as designed, as it is not possible to render the PDF view inside of the mobile app context. Make sure you set your mobile browser to allow popups so that the PDF renders seamlessly.

Løsning

Opening a Previously Uploaded PDF

If you have previously uploaded the PDF to your Files tab in Salesforce full site org, then you can use the Files record id as a parameter in the navigateToSObject() method call to navigate to the PDF view page. To find the Files record id for your PDF, if you have already uploaded it, open up the Files tab in Salesforce desktop and copy and paste the record ID from the URL for the PDF. It'll start with the "069" prefix, which is the Files record ID.

NOTE: Read our help article for a list of the standard object record IDs and their prefixes. Do not use the Attachment record ID when opening a PDF in the Salesforce for Android and iOS app environment, as the navigateToSObject call won't open the PDF.

Example of using the sforce.one.navigateToSObject() call in a VisualForce page

<apex:page standardController="Campaign">
  <script>
    sforce.one.navigateToSObject('06946000000WeeL');
  </script>
</apex:page>

Example of using lightning:navigation in a Lightning component

NOTE: lightning:navigation uses the navigate() with pageReference 

({
    handleClick: function(cmp, event, helper) {
        var navService = cmp.find("navService");
        var pageReference = {
            type: 'standard__recordPage',
            attributes: {
                recordId: '069e0000000azKYAAY',
                objectApiName: 'ContentDocument',
                actionName: 'view'
            }
        }
        event.preventDefault();
        navService.navigate(pageReference);
    }
})

Opening Dynamically Generated PDFs

If you're trying to dynamically build and display your PDF file, you will want to generate and save this file via your controller then navigate to the new ID accordingly. Generating and saving it on the server side, will eliminate conflicts noticed with the webview incorrectly handling content types across different platforms, or other rendering related issues that may occur. With this approach and navigating to the file directly, it should provide a more consistent user experience in our supported mobile environments.

NOTE: Salesforce Support cannot offer assistance in building out the functionality to dynamically generate PDFs, but we are able to assist if there is a specific error observed when attempting to render the dynamically generated PDFs.

Vidensartikelnummer

000384273

 
Indlæser
Salesforce Help | Article