using-mobile-native-capabilities
forcedotcom/sf-skills
Build LWCs that access native mobile device capabilities—barcode scanning, biometrics, location, NFC, payments, and more.
What is using-mobile-native-capabilities?
This skill routes you through building Salesforce LWCs that use native device features via the lightning/mobileCapabilities module. Use it when a user asks for barcode scanning, biometric authentication, location/geofencing, NFC, calendar/contacts access, document scanning, AR space capture, app review prompts, or payments.
- Import and gate capability services behind isAvailable() checks for graceful degradation
- Map user requests to the correct capability (11 supported: barcode, biometrics, location, NFC, calendar, contacts, document scanner, geofencing, AR space capture, app review, payments)
- Load authoritative TypeScript API definitions for each capability's factory function and service interface
- Handle typed failure codes (e.g. BarcodeScannerFailureCode, LocationServiceFailureCode) with user-actionable error messages
- Wire services into LWCs with proper availability gating, error handling, and deprecation-aware API selection
How to install using-mobile-native-capabilities
npx skills add https://github.com/forcedotcom/sf-skills --skill using-mobile-native-capabilities- LWC will run inside a supported Salesforce mobile container (Salesforce Mobile App or Field Service Mobile App)
- Familiarity with the lightning/mobileCapabilities module and BaseCapability interface
- Understanding that capabilities are unavailable on desktop and mobile web and must be gated behind isAvailable()
How to use using-mobile-native-capabilities
- 1.Identify which capability matches the user's feature request using the capability index (barcode, biometrics, location, NFC, calendar, contacts, document scanner, geofencing, AR space capture, app review, or payments)
- 2.Read the BaseCapability and mobile-capabilities shared references once per session
- 3.Open the capability-specific reference file to review the factory function, service interface, options, result types, and error codes
- 4.Import the factory function from lightning/mobileCapabilities (e.g. import { getBarcodeScanner } from 'lightning/mobileCapabilities')
- 5.Get an instance and gate every call behind isAvailable() to handle graceful fallback on unsupported surfaces
- 6.Call the non-deprecated entry point (check references for deprecated methods marked @deprecated)
- 7.Wrap the promise in try/catch and map typed failure codes to user-actionable messages (permission denied, service unavailable, user cancelled, etc.)
- 8.Verify the checklist: isAvailable() gates every call, non-deprecated APIs are used, failure codes are handled, imports are from lightning/mobileCapabilities, and no desktop/web assumptions are made
Use cases
- Scan a QR or barcode code and write the result into a Salesforce field
- Prompt for Face ID or fingerprint authentication before sensitive operations
- Capture GPS coordinates or trigger logic when a device crosses a geofence boundary
- Scan paper documents using the camera with edge detection and store as attachments
- Take an Apple Pay or Google Pay payment and surface the transaction ID to a flow
- Salesforce mobile app developers building LWCs for Salesforce Mobile App or Field Service Mobile App
- Developers adding device-native features to field service, asset management, or mobile-first workflows
- Teams integrating biometric authentication, location tracking, or document capture into mobile solutions
using-mobile-native-capabilities FAQ
Only Salesforce Mobile App and Field Service Mobile App. Desktop and mobile web will return isAvailable() = false. Always gate calls behind isAvailable().
No. These are deprecated. Use the scan(options) method instead, which is the current recommended entry point.
Each capability defines its own failure-code enum (e.g. BarcodeScannerFailureCode). Inspect error.code in the catch block and translate distinct codes into user-actionable messages.
No. The factory will return an object, but isAvailable() will return false. You must gate every call and provide a graceful fallback or user message.
The skill covers 11 capabilities: barcode scanner, biometrics, location, NFC, calendar, contacts, document scanner, geofencing, AR space capture, app review, and payments. For other features, use a different skill or consult the Salesforce mobile documentation.
Full instructions (SKILL.md)
Source of truth, from forcedotcom/sf-skills.
name: using-mobile-native-capabilities
description: "Build a Salesforce LWC that uses native mobile device capabilities — barcode scanner, biometrics, location, NFC, calendar, contacts, document scanner, geofencing, AR space capture, app review, and payments. Use this skill when the user asks for an LWC that scans a barcode, captures a photo of a document, reads location or geofences, prompts for biometrics, reads/writes the device calendar or contacts, taps NFC, takes a payment, prompts for an app review, or scans an AR space. Also triggers on "lightning/mobileCapabilities", "mobile capability", "Nimbus", "device capability". Do not use for mobile offline / Komaci priming reviews (use reviewing-lwc-mobile-offline) or for picking generic Lightning base components (use a generic Lightning base components skill)."
metadata:
version: "1.0"
Using Mobile Native Capabilities
The lightning/mobileCapabilities module exposes a set of factory functions
that return service objects for native device features (barcode scanning,
biometrics, location, etc.). Each service extends a common
BaseCapability with an isAvailable()
method, so an LWC can degrade gracefully on surfaces where the capability is
not present (desktop, mobile web).
This skill routes an agent through (1) picking the right capability, (2) loading the authoritative type definitions, and (3) wiring the service into an LWC with the correct availability gating, error handling, and deprecation-aware API choice.
When to Use This Skill
- User asks for an LWC that uses a device capability listed in the index below.
- User mentions
lightning/mobileCapabilities, "mobile capability", or "Nimbus" by name. - User wants to know which mobile native APIs are available, or which one fits their feature.
Do NOT use this skill for:
- Mobile-offline review of an LWC (lwc:if, inline GraphQL, Komaci-priming
violations) — use
reviewing-lwc-mobile-offline. - Picking generic Lightning Base Components — use
using-lightning-base-components.
Prerequisites
- Knowledge that the LWC will run inside a supported mobile container
(Salesforce Mobile App, Field Service Mobile App). These capabilities are
unavailable on desktop and mobile web; gate every call behind
isAvailable(). - Familiarity with the
lightning/mobileCapabilitiesmodule declaration (see mobile-capabilities).
Capability Index
| Capability | Reference | One-line use |
|---|---|---|
| App Review | App Review | Prompt the user for a native in-app review. |
| AR Space Capture | AR Space Capture | Capture a 3D scan of a physical space using AR. |
| Barcode Scanner | Barcode Scanner | Read QR / UPC / EAN / Code-128 / etc. from the camera. |
| Biometrics | Biometrics | Authenticate via Face ID / fingerprint. |
| Calendar | Calendar | Read or create events on the device calendar. |
| Contacts | Contacts | Read or create entries in the device address book. |
| Document Scanner | Document Scanner | Scan paper documents using the camera with edge detection. |
| Geofencing | Geofencing | Trigger logic when the device crosses a geographic boundary. |
| Location | Location | Read GPS coordinates and watch for updates. |
| NFC | NFC | Read or write NFC tags. |
| Payments | Payments | Take an Apple Pay / Google Pay payment. |
Workflow
Step 1 — Identify the capability
Map the user's feature ask to one row of the capability index. If the ask spans multiple capabilities (e.g. "scan a barcode and store it on a contact"), plan for each capability separately — there is one factory function per capability.
Step 2 — Load the shared and capability-specific references
Read these two shared references once per session — they apply to every capability and are not duplicated in the per-capability files:
- BaseCapability — the common interface
with
isAvailable()that every service extends. - mobile-capabilities — the
lightning/mobileCapabilitiesmodule declaration showing every re-exported service.
Then open the capability's reference file from the table above. Each per-capability reference contains the service-specific TypeScript API (factory function, service interface, options types, result types, error types) and assumes the two shared references above are already in context.
Do not infer the API from memory — read it. The services evolve and some
methods are explicitly @deprecated in favor of newer alternatives.
Step 3 — Wire the service into the LWC
For each capability:
- Import the factory from
lightning/mobileCapabilities:import { getBarcodeScanner } from 'lightning/mobileCapabilities'; - Get an instance:
const scanner = getBarcodeScanner(); - Gate the call behind
isAvailable():if (!scanner.isAvailable()) { // graceful fallback or user message return; } - Call the non-deprecated entry point. Several services keep older
methods marked
@deprecatedalongside the recommended one — always prefer the recommended method in the reference. - Wrap the promise in
try/catchand handle the typed failure codes the service exposes (e.g.BarcodeScannerFailureCode,LocationServiceFailureCode). User-cancelled vs. permission-denied vs. service-unavailable are distinct UX states.
Step 4 — Surface failure modes to the user
Each service defines its own failure-code enum. Translate codes into
user-actionable messages: a USER_DENIED_PERMISSION should ask the user to
grant permission; a USER_DISABLED_PERMISSION must direct them to the OS
settings; a SERVICE_NOT_ENABLED should be a developer-visible error, not
shown to the user.
Step 5 — Stay inside the supported surface
Mobile capabilities are available only when the LWC runs inside a
supported Salesforce mobile app. If the same component is rendered on
desktop or mobile web, the factory will still return an object but
isAvailable() will return false. Never assume availability — gate every
call.
Examples
Example — "Scan a barcode and write it into a field"
- Map to: Barcode Scanner.
- Read Barcode Scanner.
- Use
scan(options)(not the deprecatedbeginCapture/resumeCapture/endCapturetriple). - In options, set the
barcodeTypesto the symbologies needed (default is all supported types) andenableMultiScan: falsefor a single read. - On resolve, write
result[0].valueto the bound field. On reject, inspecterror.codeagainstBarcodeScannerFailureCode.
Example — "Take an Apple Pay payment for an order total"
- Map to: Payments.
- Read Payments.
- Gate on
isAvailable(). - Build the payment request object per the reference.
- On resolve, surface the transaction id to the calling flow. On reject, handle user-cancelled and payment-failed paths separately.
Verification Checklist
- Every capability call is preceded by
isAvailable(). - The non-deprecated entry point is used (no
beginCapture/resumeCapture/endCapturefor barcode, etc.). - Each rejection path is mapped to the typed failure code enum.
- Imports come from
lightning/mobileCapabilities, not from a private path. - No assumption that the capability runs on desktop or mobile web.
Troubleshooting
isAvailable()returnsfalseon a real device — the device is running an unsupported app surface (not Salesforce Mobile or Field Service Mobile), or the service is gated by an org-level setting. The fix is org configuration, not code.- TypeScript can't find the import — confirm the LWC has access to
lightning/mobileCapabilities. The module is declared globally inside Salesforce mobile containers; outside that, the types must be installed separately. - Deprecated barcode methods still work — yes, but new code must use
scan()anddismiss(). Refactor any sample code the agent received before returning it. - Multiple capabilities in one component — get separate instances per capability (they are independent service objects); do not try to share state between them.
Related skills
More from forcedotcom/sf-skills and the wider catalog.

using-ui-bundle-salesforce-data
Access Salesforce records in UI bundles using the Data SDK with GraphQL and REST APIs.

validating-slds
Audit Lightning Web Components for SLDS compliance and produce a scored quality report. Runs the SLDS linter, analyzes CSS for theming hook usage and pairing, checks HTML for accessibility attributes, and scores findings across categories into an overall grade. Use when asked to \"score my component\", \"SLDS scorecard\", \"quality report\", \"audit SLDS compliance\", \"how good is my SLDS\", \"check component quality\", \"rate my component\", \"evaluate my component\", \"is this component ready to ship?\", \"look at my LWC for issues\", \"audit this before I submit\", \"review my component before code review\", or any time a user wants a quality assessment or production-readiness check on an LWC or SLDS component. Not for fixing violations (use uplifting-components-to-slds2) or building new components (use applying-slds).

activating-datacloud
Manage Salesforce Data Cloud activations, targets, and downstream delivery of audiences and data.

analyzing-omnistudio-dependencies
Detect namespaces, map dependencies, and visualize impact across OmniScripts, FlexCards, Integration Procedures, and Data Mappers.

karpathy-guidelines
Behavioral guidelines to reduce common LLM coding mistakes through explicit assumptions, simplicity, surgical changes, and verifiable success criteria.

loop-library
Legacy compatibility alias for Loopy—use Loopy for new installations.