How do you build and deploy a custom LWC for the Salesforce Field Service mobile app so it works offline?
Answer
Custom LWCs can run inside the Field Service mobile app as quick actions or on record pages.
Build steps
- Create the LWC and expose it for the right target in
js-meta.xml. - Use Lightning Data Service (
getRecord,updateRecord, GraphQL wire adapter) so data works offline. Imperative Apex calls need a connection. - Add the component as a quick action (Lightning Component, screen action) to the object's layout or the mobile action list.
- Make sure the records and fields it needs are in the Briefcase.
- Deploy with the CLI or a change set, and test on a real device in airplane mode.
xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordAction">
<actionType>ScreenAction</actionType>
</targetConfig>