Implementation of Barcode Scanner API in Salesforce

By Shivank Gairola 03-Feb-2023

Barcode Scanner API implementation in Salesforce can streamline data entry and tracking. A few weeks back I got a chance to implement the barcode scanner API provided by Salesforce. A barcode scanner is a device that reads and captures information from a barcode. Salesforce recently released a new Barcode API which now supports barcode scanning natively on LWC for mobile devices. It is a JavaScript module that provides an API to Lightning web components. I was required to capture the product information from the barcode and create respective product records. The functionality only works on mobile devices. We use the Lightning web component which can use a mobile device’s camera and mobile OS platform features to scan a barcode.

Benefits:

Simplify your Salesforce data entry process with Barcode Scanner API integration. This guide covers the benefits, implementation, and best practices for success.

  • It’s easy to install the information in Barcode.
  • Barcodes eliminate the possibility of human error.
  • A barcode system reduces employee training time.
  • Barcodes are inexpensive to design and print.
  • Data obtained through barcodes is available rapidly.

Below is the path on how to use it in LWC: –

  • Import lightning/mobile capabilities
  • Initiate scanner variable using method getBarcodeScanner()
  • Set configuration suggesting which barcodes are supported
  • Use begin Capture() method to launch mobile camera
  • Read the result or handle error

Different types of barcodes that are available for scanning are: –

  • CODE_128
  • CODE_39
  • CODE_93
  • DATA_MATRIX
  • EAN_13
  • EAN_8
  • PDF_417
  • ITF
  • QR
  • UPC_E

Use Case:

Scan a product barcode from the mobile and decode the value in the barcode to create a record in Salesforce.

Solution:

  • Create a new custom object (Product__c) and tab to capture the product information.
  • A tab is accessible through the salesforce mobile app.
  • Create an LWC component of the barcode scanner and deploy all components to the org.
  • Place it inside the Object page and make it available for mobile users.
  • Through the barcode scanner, scan product details and create a new record in Salesforce.

LWC.html

LWC.js

LWC.js-meta.xml

About the Author

      Book a Consultation