Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
iampatrickbrinksma authored Oct 31, 2024
1 parent e230607 commit eb94c56
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Before using this code in a production environment, it is crucial that you:
By using this code, you acknowledge that Salesforce is not liable for any issues that may arise from its use.

## Components Included In This Repository
* Prime Files for Offline Use
* Online of Offline
* Check In/Out
* File Upload Plus
Expand All @@ -24,8 +25,20 @@ By using this code, you acknowledge that Salesforce is not liable for any issues
* Web Storage API
* Debug Panel

# Prime Files for Offline Use (scheduleFilePrimer)
This component downloads files related to Work Orders and Work Order Line Items which are parent records of the service appointments which make up the schedule of the service resource. Today (Winter '25), Salesforce Field Service does not have an out of the box feature to prime files for offline use. The user has to open a file for it to be available for offline use, which can be a cumbersome task for a service resource. The component is able to download any file due to the behavior of the underlying runtime engine that causes the app to download any file that is references in an IMG tag in the template. Additionally, all the details of the records of the `ContentDocumentLink`, `ContentDocument` and `ContentVersion` objects need to be primed as well to be able to view the files when the device is offline using the native file preview component.

The folowing components are part of this example:
* Lightning Web Component: `filePrimer`
* Lightning Web Component: `recordFilePrimer`
* Lightning Web Component: `scheduleFilePrimer`

In order to use the component create a Lightning Web Component `Global Action` which uses the `scheduleFilePrimer` LWC and add it to the `Mobile & Lightning Actions` section on the `Publisher Layout` which is assigned to the profile of the mobile user. This allows the user to prime files related to the Work Orders and Work Order Line Items which are part of their schedule for the given number of days.

In order to allow the user to prime files related to a record, use the `recordFilePrimer` LWC, create the object specific `Quick Action` and add it to the `Mobile & Lightning Actions` section on the `Page Layout` which is assigned to the profile of the mobile user.

# Online Or Offline (isOnlineOrOffline)
This component can detect if the LWC is online or offline. Today (Spring '23 release) there is no standard method in LWC to detect this. By using imperative Apex with a simple Apex method it can be derived if the LWC is online or offline. It is important to understand that the online and offline state is not detected automatically and it only works on demand.
This component can detect if the LWC is online or offline. Today (Winter '25) there is no standard method in LWC to detect this. By using imperative Apex with a simple Apex method it can be derived if the LWC is online or offline. It is important to understand that the online and offline state is not detected automatically and it only works on demand.

The parentComponent LWC has embedded this component to show how it can be used and how it behaves.

Expand Down Expand Up @@ -55,14 +68,14 @@ Note: This is NOT possible via the Profile or Permission Set in the Setup UI. Ho
1. Navigate to Setup -> Object Manager -> Service Resource -> Fields & Relationships -> Last Known Location -> Set Field-Level Security and make sure the Visible option is checked for the Profile of the mobile user.
2. For the Last Known Location Date, update the URL of step 1 from `.../lightning/setup/ObjectManager/ServiceResource/FieldsAndRelationships/LastKnownLocation/edit...` to `.../lightning/setup/ObjectManager/ServiceResource/FieldsAndRelationships/LastKnownLocationDate/edit...`, so changing `LastKnownLocation` to `LastKnownLocationDate`

# File Upload Plus
# File Upload Plus (fileUploadPlus)
Inspired by the example code in [the Saleforce documentation](https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/use_images_upload_while_offline_example.htm) this component allows you to upload a single file (any file type) and populate a custom field define on the `ContentVersion` object. You can embed this component in another LWC and pass the record Id and custom field API Name, Label, field type (text and checkbox supported) and a default value. Additionally it dispatches a custom event on file upload and when the upload is canceled.

Important: You have to logout and login or clear metadata cache to obtain the metadata of the custom field defined on the `ContentVersion` object. This object does [not support field level permissions](https://help.salesforce.com/s/articleView?id=000380808&type=1), and any user will have access to the custom field.

An example of how to use the File Upload Plus component is shown in the ```attachFileToWorkOrder``` LWC, which uses the ```Internal_Only__c``` custom checkbox field on the ContentVersion object. Make sure to create/deploy that field in order to use this LWC. Add the LWC as an Action to the Work Order to expose it in the Field Service Mobile app.

# Object Details
# Object Details (objectDetails)
The `getObjectInfo` wire adapter from the `lightning/uiObjectInfoApi` module can be used to read the metadata information from a SObject to determine what Record Types are accessible for the user, or if a field is updatable, etc. It can also be used to make sure the SObject metadata is primed and available for offline scenarios. This LWC component provides an easy way to view and navigate the `getObjectInfo` results.

Screenshot:
Expand All @@ -71,7 +84,7 @@ Screenshot:

Additionally, because a wire is used to call the Apex method, the results are cached locally and the data is available in offline scenarios.

# Prime Custom Metadata Types
# Prime Custom Metadata Types (primeCustomMetadata)
Custom Metadata Types are a great way to define custom application metadata which is customizable, deployable, packageable, and upgradeable. Currently (Winter '25) it is not possible to prime Custom Metadata Types for offline scenarios using the Briefcase Builder nor GraphQL in a Lightning Web Component. However, by using an Apex wire it is possible to prime Custom Metadata Types for offline use.

The following components are part of this example:
Expand All @@ -94,13 +107,13 @@ Clear the metadata cache in the SFS mobile app, and when you open the Global Act

This data is also available for offline use, as the SFS mobile app will prime the data via the Apex wire, and store it in the local cache. This local cache is separate from the data cache and is immutable.

# Generate Deep Link Urls with Signature
# Generate Deep Link Urls with Signature (recordDeepLinks)
When using Deep Linking to navigate from an external app, or from within the app, to the Field Service mobile app certain deep link urls need to be signed in order for the security dialogue to be suppressed, see help doc: https://developer.salesforce.com/docs/atlas.en-us.field_service_dev.meta/field_service_dev/fsl_dev_mobile_deep_linking_hide_security_dialog.htm.
This example shows how to generate the signature in Apex for links that are "static" in nature, meaning they just rely on the Salesforce record Id and not dynamic parameters. The example includes an Apex class with a method to generate the deep link urls for a record and store them in a custom field, and a Lightning Web Component to use it in the mobile app.

The folowing components are part of this example:
* Apex Class: `DeepLinkUrl`
* Lightning Web `Component: recordDeepLinks`
* Lightning Web Component: `recordDeepLinks`
* Custom Field: `ServiceAppointment.Deeplink_Url__c`
* Quick Action: `ServiceAppointment.Deep_Link_Urls`
* Permission Set: `Field_Service_Deep_Linking_Permissions`
Expand All @@ -125,7 +138,7 @@ update new ServiceAppointment(Id = saId, Deeplink_Url__c = deepLinkUrls);

Then open the mobile app, navigate to the service appointment and open the `Deep Link Urls` action and test the deep linking.

# Web Storage API
# Web Storage API (webStorageAPI)
The `Web Storage API` (https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) allows you to store key / value pairs in the browser storage. This can be useful when developing LWCs for the SFS mobile app. The `webStorage` LWC is a class that enables the use of the Web Storage API, and the `webStorageAPI` component is an example of the use of this class.
It's important to understand the difference between the storage types supported, which are:
* `sessionStorage` - Stores data as part of when the SFS mobile app is open. When it's force closed, or closed by the mobile operating system, the storage is lost.
Expand All @@ -141,7 +154,7 @@ To use this LWC, create a Global Action referncing the LWC and add it to the app
* The storage is not encrypted at rest by the SFS mobile app
* It is recommended to use this only in specific use cases whereby the state of an LWC needs to be restored

# Debug Panel
# Debug Panel (debugPanel)
It can be challenging to debug your Lightning Web Component while running it in the Salesforce Field Service mobile app. This Debug Panel component provides an easy way to write debugging information into a text area with timestamps added. The panel allows you to copy the text to the clipboard and clear the output.

Example of how it looks embedded in an LWC:
Expand Down

0 comments on commit eb94c56

Please sign in to comment.