Salesforce LWC to Scan barcodes using mobile camera (Only Mobile Salesforce App) as well as to Create a QR Code for any content. (Desktop & Mobile)
Salesforce had released a new BarcodeScanner API which supports barcode scanning natively on LWC for mobile devices using the Salesforce Mobile App. Since it’s supported natively, we don’t need to worry about maintaining 3rd party Javascript, Locker services, performance issues, etc.
This Salesforce LWC Component contains methods to Scan any of the Supported Bar Codes by Salesforce and also provides an ability via JavaScript file to Create a QR Code out of user-entered string content. QR Code Generation can be done on Desktop or Mobile experience whereas the Bar Code scanning works in Salesforce Mobile App only.
For Scanning Bar Codes, steps involved are-
- import
getBarcodeScanner
fromlightning/mobileCapabilities
- initiate scanner variable using method
getBarcodeScanner()
- set configuration suggesting which supported barcodes are needed to scan
- use
begineCapture()
method for launching mobile camera - read the scanned result or handle error accordingly, concluding with
endCapture()
Mobile View =
Desktop View =
Scanned Examples on Mobile =
- Waseem Ali Sabeel - @WaseemAliSabeel 🤠
Reach out at one of the following places!
- Website at sfwiseguys.wordpress.com 🎩
- Twitter at @sfwiseguys