Loading

Salesforce Mobile Development Best Practices

Publiseringsdato: Aug 8, 2025
Beskrivelse

There are some things to be aware of when developing custom pages for the Salesforce Mobile App. This article will go over some of those scenarios. This is by no means an exhaustive list. 

Løsning

Salesforce Mobile App Architecture

Salesforce for iOS and Android is a “hybrid” app, meaning that it is a mobile web application built using JavaScript, HTML5, the Aura framework (one.app). This app is wrapped in a Salesforce container (bridge.app) that allows the app to utilize features of the native mobile platform (iOS, Android), to be served via desktop and mobile web browsers, as well as downloaded via the App Store or Google Play Store. For more differences on native and HTML5 apps, check out the Get Started with Salesforce Mobile SDK trailhead Get Started with Salesforce Mobile SDK

Visualforce Best Practices

1. Visualforce landing page and performance
Avoid using a Visualforce page as the first tab in the mobile app navigation menu, as loading time of the app can increase if complex business logic runs on the app's landing page. If a Visualforce page must be used as the landing page follow these guidelines:
  • Minimize complexity of business logic, and link to more complex Visualforce pages with a button click.
  • Minimize all CSS and JavaScript libraries, and utilize lazy loading of the page to allow for basic HTML to load first, then additional custom libraries second.
  • Additional ways to improve performance in Visualforce pages in the mobile app are by utilizing JavaScript Remoting. 

 

2. Navigation to or from a Visualforce page
When navigating to or from a Visualforce page in full site, the Page Reference class can be used to instantiate a new URL of the updated Visualforce page, or to navigate to a second Visualforce page. In the Salesforce mobile app, it is unsupported to return a Page Reference class to navigate to a new URL or a second Visualforce page. As a workaround, set the return statement in your function using the Page Reference class to return "null", and add conditional logic for the mobile-supported sforce.one JavaScript library to be used to navigate to the new page. An example of how to build out conditional navigation logic in the Visualforce page can be found in Sharing Visualforce Pages between Mobile and Desktop

 

3. Opening a PDF or Excel document from a Visualforce page
It is possible to open a PDF or Excel file from a Visualforce page when those documents have previously been saved in the Files tab in your org. However, for dynamically generated PDF or Excel files, these sometimes cannot be rendered in the Visualforce page, as the mobile app's webview does not render custom content types. The workaround we suggest is to refactor your controller code to save a copy of the PDF or Excel file in your Files tab in the Salesforce org. That way, you can utilize the sforce.one navigation call in your Visualforce page, to navigate to the file using the file's record id as a parameter in the sforce.one.navigateToSObject() call. More documentation on this can be found in the Open a PDF with Salesforce for Android and iOS app knowledge article. 

4. Window.open calls to open a new Visualforce page
Although full-site browsers support window.open calls to open a new Visualforce page, these are not supported in the Salesforce mobile app environment, because this call causes the code to break out of the main container of the Salesforce mobile app, which is not allowed for security reasons. As a workaround, we suggest using conditional logic to utilize the sforce.one navigation library , if a user is accessing the Visualforce page via the Salesforce mobile app. An example of how to build out conditional navigation logic in the Visualforce page can be found in Sharing Visualforce Pages between Mobile and Desktop.

5. Unsupported Visualforce components
There are some Visualforce components that are not supported for use in the Salesforce mobile app. For example, any Visualforce tag that does not have the <apex> namespace is not supported. Support will not troubleshoot these issues and developers are encouraged to refactor their code to align with mobile app best practices.

 

Lightning Components Best Practices

1. Lightning component as landing page and performance
Due to increased latency observed in app loading time with certain Lightning component landing pages in the Salesforce mobile app navigation menu, avoid using a Lightning component as the landing page for the Salesforce mobile app if possible. If a lightning component must be used as the landing page, follow these guidelines:

  • Minimize complexity of business logic, and link to more complex Lightning components with a button click, so that these do not load upon initial user login to the app.
  • Minimize all CSS and JavaScript libraries, and utilize lazy loading of the page to allow for basic HTML to load first, then additional custom libraries second.

2. Lightning pages in the Salesforce mobile app 
Lightning *app* pages are the only supported Lightning pages for the Salesforce mobile app. Lightning record pages are now supported in mobile app. If you would like to leverage Lightning component functionality in the mobile app, you have two options:

  • Create a Lightning app page and add the lightning component to it. This type of page will work in Lightning Experience's full site as well as the Salesforce mobile app. 
  • Add the lightning component as a custom action override to the desired object's record page. This will allow you to tap a custom action on a record page, and that action will launch the lightning component. Instructions for this can be found in Creating an Aura Component for Use as an Action Override

3. Force:NavigateToComponent to navigate between lightning components
The force:navigateToComponent call has been deprecated as of Summer '18, to be replaced with the lightning:navigation event. In scenarios where customers are using the lightning:navigation call, we strongly encourage developers to nest the additional lightning component(s) as children within the first lightning component. That way, the child lightning components are generated dynamically. Here are instructions for how to do this.  

4. Lightning out 
Lightning out is the practice of embedding a lightning component(s) inside of a Visualforce page. It can be observed when the “Lightning.use” statement is added to a Visualforce page. Developers may choose to set up this functionality so that lightning components can be accessed in the Salesforce Classic full site UI. Lightning out is a Beta feature, and as such is not supported for use in the Salesforce mobile app. Support cannot provide debugging for a Beta feature, and we strongly recommend customers remove Lightning out code from their Visualforce page, and refactor their code to launch the lightning components via a lightning component tab or an record action override. 

5. Supported lighting components & SLDS styles
Please be aware that not every component that is available for full-site development, is supported when leveraging it from a mobile-enabled device or our mobile app. Please review our Lighting Component Developer Guide: Component Reference , for more details on each component.

Please also note that some Lightning component documentation will not call out that components are unsupported for mobile. This documentation ‌may say, "This component inherits styling from ... in the Lightning Design System". If you see this message, please be sure to review the link to the Lightning Design System documentation. Styling can have its own caveats depending on the functionality that is used. Confirm that the Lightning Design System documentation does not say "Desktop Only", as this means this style is unsupported for use in the Salesforce mobile app. 

We are still working on aligning these two documents and will be pushing to make this desktop-only verbiage available on the component reference as well, but for the time being, if you run into any rendering issues or odd behavior across the different environments, please confirm that all components and inherited styling you leverage are documented to be supported in the mobile environment. 

6. Window.open, window.location, location.href methods unsupported
These document based calls are not supported for use within Lightning components in the Salesforce mobile app environment, because they cause the code to break out of the main container of the Salesforce mobile app, which is not allowed for security reasons. These calls may work for a time, but because they are not tested by our Product team with the Salesforce mobile app, this functionality may break with any update to the app. Instead, to navigate to URLs, use lightning:navigation with the standard__webPage  attribute. 

Additional Reference : Salesforce Mobile App

Knowledge-artikkelnummer

000384134

 
Laster
Salesforce Help | Article