Scan a Barcode in a Lightning Web Component (Beta)
Use the BarcodeScanner API to add barcode scanning to your Lightning web components. Scan UPC, QR, and other standard barcode types from Lightning components running on a mobile device. Look up product details, record inventory scans, save contact details from a conference badge—your code, your way!
Where: This feature is available in Lightning web components when they’re running in the Salesforce mobile app or Mobile Publisher.
Why: Improvements to the BarcodeScanner API in this release include the following.
- Added resumeCapture() to allow continuous scanning of multiple barcodes.
- Increased control over the scanning user experience.
- Improved error handling and error responses.
How: Using BarcodeScanner in your Lightning web component is straightforward.
- Import BarcodeScanner into your component definition.
- Test to make sure BarcodeScanner is available before you call scanning lifecycle functions.
- Use the scanning lifecycle functions to start and stop scanning.
For complete details, see Scan Barcodes on a Mobile Device in the Lightning Web Components Developer Guide.