Custom Barcode Scanner in Salesforce

custom barcode scanner in salesforce

Why Barcode Scanner ?

In Quality Management Systems dealing with large volumes of products, barcode scanners streamline inspections by rapidly capturing product IDs encoded in barcodes. This enables efficient and accurate recording of inspection outcomes directly in the system, significantly reducing manual input time and minimizing the risk of errors. The integration of barcode scanners in such scenarios enhances the scalability and effectiveness of quality control processes within the system.

In the fast-paced world of modern sales, where efficiency and precision are paramount, integrating a customized barcode scanner into your Salesforce ecosystem can be a game-changer. This transformative technology not only streamlines sales processes but also enhances accuracy and productivity, empowering your sales team to achieve new heights. In this comprehensive guide, we will delve into the intricacies of building and implementing a bespoke barcode scanning solution tailored specifically for Salesforce. From concept to execution, join us on a journey of innovation as we explore how this customized tool can revolutionize your sales workflow and elevate your business operations.

For this, we use:

  1. Lightning Web Component
  2. Apex Class

Unlocking a new realm of convenience and efficiency, Lightning web components have the capability to leverage the camera and native features of a mobile device for seamless barcode scanning. Whether it’s deciphering a UPC symbol, capturing a QR code or Data Matrix, this functionality empowers users to effortlessly integrate barcode scanning into their Salesforce experience. Upon a successful scan, the Lightning web component receives the decoded data directly, eliminating the need for network connectivity during the scanning process. It’s important to note that the BarcodeScanner functionality relies on access to platform-specific APIs, exclusively accessible within compatible Salesforce mobile apps, ensuring a smooth and secure integration with the mobile operating system.

					import { getBarcodeScanner } from 'lightning/mobileCapabilities';


To seamlessly integrate barcode scanning functionality, the Lightning web component employs the powerful “getBarcodeScanner” API, accessible through the ‘lightning/mobileCapabilities’ module. This API harnesses the capabilities of a mobile device’s camera and native features, allowing the Lightning web component to effortlessly scan various barcodes, including UPC symbols, Data Matrix or QR codes. Upon successful scanning, the component successfully retrieves the decoded data, ensuring a smooth and responsive user experience. It’s worth noting that this advanced functionality requires access to platform-specific APIs, available exclusively within compatible Salesforce mobile apps, guaranteeing a secure and optimized integration with the mobile operating system.

Process Flow:

Barcode Scanner process flow

Html Component:

        <lightning-button variant="brand" label="Scan Barcode" title="Scan Barcode" 
            onclick={handleBarcodeClick} class="slds-m-left_x-small"> 

.Js-meta.xml Component:

					<?xml version="1.0"?>
<LightningComponentBundle xmlns="">
    <masterLabel>Barcode Scanner</masterLabel>

Js Component:

					import {LightningElement,api,wire,track} from 'lwc';
import { getBarcodeScanner} from 'lightning/mobileCapabilities';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import insertNew from '@salesforce/apex/BarcodeScannerController.insertNew';

export default class BarcodeScanner extends Lightning Element {

@api storeValue
@api scannedBarcode = '';
 * When component is initialized, detect whether to enable Scan button
connectedCallback() {
   this.myScanner getBarcodeScanner();
 * Method executed on click of Barcode scan button 
 * @param event

     if(this.myScanner.isAvailable()) {
          const scanningOptions = {
                      barcodeTypes: [this.myScanner.barcodeTypes.QR,
                   instructionText: 'Scan a Barcode',
                   successText: 'Scanning complete.'
          .then((result) => {
                             this.scannedBarcode result.value;
                             insertNew({storeValue: this.scanned Barcode)).then(result => {

                                 //put to do action here

                                 // put error message here
          .catch((error) => {
          .finally(() => {
          this.showError('Error','Scanner not supported on this device');

Apex Class:

					public with Sharing class Barcode ScannerController{

public static String insertNew(String storeValue){
       List<Account> createAcc = new List<Account>();
       Account newAcc = new Account();
       newAcc.Scanned_ID__c = storeValue;
       String ids =;
       return ids;

Custom Button using the above LWC component:

scan barcode


Note: While the barcode scanner functionality is a powerful asset for enhancing user experience in Salesforce, it’s essential to note its compatibility nuances. When accessed over a web browser, the barcode scanner may not be fully supported. However, the good news is that its capabilities come to life seamlessly when utilized within the mobile publisher for Salesforce Experience Cloud.

Leave a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

dreamforce 2024
Dreamforce 2024: A 3-Day Event of Learning, Connection, and Inspiration
how-can-slaesforce b2b commerce cloud increase customer engagement
How Can Salesforce B2B Commerce Cloud Increase Customer Engagement
salesforce for financial services transforming customer engagement operational effectiveness
Salesforce for Financial Services: Transforming Customer Engagement & Operational Effectiveness
einstein copilot transform your salesforce experience
How Einstein Copilot Actions Can Transform Your Salesforce Experience
how can salesforce experience cloud drive customer engagement rates
How Can Salesforce Experience Cloud Drive Customer Engagement Rates?

How can i help you? close button

powered     by   ABSYZ
Scroll to Top