Lightning Component to scan barcodes using Salesforce1
Couple of things to note:
- Although quaggaJS library supports live streams, I only implemented scanning from a file(static image) because iOS doesn’t support MediaDevices API
- Haven’t tested this in production, so use at your own risk. My recommendation is to use a stand alone native app for barcode scanning and integrate with Salesforce but if you don’t have high volume / high precision scanning requirements, this could work
- Integrating a 3rd party stand alone scanner application with Salesforce1 is not straight forward yet as there is no support for URL deep links to VF pages or lightning components (yet). Once (and if) such a support is available in Salesforce1, you won’t need this component
- Finally, Locker Service issues with object proxies prevented me from using the script directly in the component. So, I had to use a iframe for just processing the barcodes. ‘Lightning Containe’ is another option although that is still in developer preview.
Now, the fine print.. At the time of writing this blog, I am employed with Salesforce as an Architect. However, any code samples and declarative approach provided here are purely for experimental purposes and comes with no warranty or support. Matter of fact, all opinions and approach provided in this blog are purely my own and has nothing to do with my employer. It is assumed that you have the right Salesforce configuration and coding skills and will use the ideas presented here as you see fit, in your landscape. The primary purpose of this article is just to share the knowledge and my own experience. Nothing more, nothing less. Use this approach at your own risk