Giter Site home page Giter Site logo

s1barcodescanner's Introduction

Barcode Scanner Lightning Component

This project contains sample code for native barcode scanning in Salesforce1. It contains a custom Lightning component that can be attached to a custom quick action on account record. On tapping the quick action in Salesforce1, it will launch this QR Code Reader app on the device to scan a barcode. Once scanned, the control is returned to a Visualforce page for attaching the scanned barcode as an 'Asset' to the account record. Once successfully attached, the Visualforce page redirects the user to asset record in Salesforce1 for further updates.

Salesforce1 for iOS doesn't support URL deeplinking of Visualforce pages (yet). It currently (as of Mar'2017 / Version 12.0) only supports deeplinking to a specific record. Please check here for more information. In most cases, after scanning the barcode, you may want to pre-process before navigating the user to a record in Salesforce1. For e.g., in this sample, the user scans a barcode that is attached as an asset to the account. Since VF deeplinking is not supported in Salesforce1 (iOS), this component launches the VF page within the device browser before getting the user back to Salesforce1. Since Winter '17 release, Apex supports creating access tokens (aka Session IDs) using JWT flow. This component, uses the JWT flow to generate an accesstoken so that the user is not prompted to authenticate in the intermediate VF page. Please check here for more information.

When (and if) Salesforce1 for iOS supports VF deeplinking, you won't need the JWT flow (and in Android, you won't need this JWT flow either as Salesforce1 in Android already supports VF deeplinking). The component can simply launch the Scan app and have it return the control back to Salesforce1. Until then, you can use this trick to enable pre-processing. Follow the below steps to install this in your Developer or Sandbox org

  1. Click 'Deploy to Salsforce button at the end of this page'
  2. Once deployed, go to Setup->Administer->Security Controls->Certificate and Key Management
  3. Create a Self Signed Certificate. Note down the Unique Name and download the certificate to your desktop/laptop
  4. Next, create a connected app (Setup->Create->Apps->Connected Apps->New)
  5. Make sure 'Enable OAuth Settings' is checked; callback URL can be something like 'barcode:///mobilesdk/detect/oauth/done'
  6. Choose required oAuth scopes (Full access is good for testing but for production you may want to choose the appropriate ones)
  7. Make sure 'Use Digital Signatures' is checked. Click 'Choose File' and upload the certificate that you downloaded step 1
  8. Save the connected app and note down Consumer Key
  9. On the connected app page click 'Manage' and then click 'Edit Policies'
  10. Under 'OAuth Policies' choose 'Admin approved users are pre-authorized'. Save
  11. Click on 'Manage Profiles' or 'Manage Permission sets' and attach the profiles/permission sets of users that will be using this component
  12. Now go to Setup->Administer->Security Controls->Remote site settings->New Remote site. Add an entry for "https://login.salesforce.com" (https://test.salesforce.com for sandbox)
  13. Then go to Setup->Build->Develop->Custom metadata types->S1JWTAuth->ManageS1JWTAuth. Cick 'New'
  14. Add an entry with label as below
  • Label: Barcode Scanner
  • S1JWTAuth Name = Barcode_Scanner
  • Consumer key = Key from step 8
  • Certificate Name = Certificate name from step 3
  1. Add a custom quick action to Accounts of type 'Lightning Component'. Choose the component 'c:S1BarcodeScanner'
  2. Place this custom quick action in pagelayout (under Salesforce1 panel)
  3. Download this QR code app from app store "https://itunes.apple.com/us/app/qr-code-reader-by-scan/id698925807" (Check google play store for Android version)
  4. Launch the Salesforce1 app, tap on an account, tap on the quick action you create above, this should open up the scan app, scan a barcode and once done, will launch a VF page in Safari, create an asset record for the account and navigate you back to Salesforce1 to edit the created asset record.

Note: This project uses the free version of Scan app, however, for production code, you may want to invest in a commercially available barcode scanner app that allows URL deeplinking.

Deploy to Salesforce

s1barcodescanner's People

Contributors

kumarrk21 avatar

Stargazers

 avatar Wnakiri119 avatar  avatar Francesco Martire avatar Vince avatar

Watchers

James Cloos avatar Francesco Martire avatar  avatar  avatar

s1barcodescanner's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.