To open one or more file records in Lightning Experience and the Salesforce app, use the navigation service,
lightning/navigation. The navigation service opens the preview of one or more files in a modal dialog in Lightning Experience, or triggers a file download in the Salesforce app on mobile devices.
The navigation service uses a
PageReference, which describes a page, or in this case, a file.
Use a page reference with
'type': 'standard__namedPage' and a
pageName attribute of
filePreview named page value supports the ContentDocument and ContentHubItem (external files) objects. The
filePreview named page value is supported in Lightning Experience and all versions of the mobile app. It isn’t supported in other containers, such as Lightning Components for Visualforce, Lightning Out, or Experience Cloud sites. The page value isn’t supported even if you access these containers inside Lightning Experience or the Salesforce mobile app.
This example opens the record with ID
069xx0000000001AAA in Lightning Experience and the Salesforce app.
recordIds property is a comma-separated list of all record IDs available for download.
In Lightning Experience, the record specified in
selectedRecordId downloads first. The user can switch to the other records by clicking the arrows in the app. The desktop file previewer offers image and SVG-based multi-page office documents preview, presentation mode, and quick access to file actions like share, download, upload, and delete.
In the Salesforce app, a single file downloads when the event is fired. If
selectedRecordId is specified, that file downloads. If
selectedRecordId isn’t specified, the first file in the
recordIds list downloads. Depending on the device, a native preview of the file displays.
- PageReference Types
- Salesforce Object Reference Guide: ContentDocument
- Salesforce Object Reference Guide: ContentHubItem