Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Thursday, May 29
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Extract Driver License Detail from Image using Einstein API

    Extract Driver License Detail from Image using Einstein API

    Dhanik Lal SahniBy Dhanik Lal SahniAugust 17, 2021Updated:June 11, 20232 Comments4 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Extract Driver License Detail from Image using Einstein API
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Einstein Vision API help to extract text from different image formats. We can extract information from any tabular data, form data or business card’s image. This post will give step by step information about extracting driver license detail from Image using Einstein API in Salesforce.

    This post will be applicable for extracting below other type of form image data extraction.

    • Driver’s License
    • Form 1040
    • Form W-2
    • Passport
    • Pay Stub
    • Permanent Resident Card

    This process will help us in getting data extracted immediately and reduce lot of time to process that information. Some time it can help govt agency like passport office, transport office in validating detail faster and can help in taking decision on time.

    Steps to integrate Salesforce and Einstein Vision API

    1. Create account in Einstein Platform Services
    2. Create Private Key and Generate Token
    3. Call Einstein OCR API from Apex
    4. Extract image data in Case object
    5. Test Code

    1. Create account in Einstein Platform Services

    Setup account at https://api.einstein.ai/signup. See step 1 from Create OCR App using Salesforce Einstein OCR API for more detail

    2. Create Private Key and Generate Token

    Create private key and token to call API. Check step 2 from Create OCR App using Salesforce Einstein OCR API for more detail

    3. Call Einstein OCR API from Apex

    After setting up API and authentication detail, we are now ready with API call which will extract detail from uploaded image in case record. For this blog, I am using case object but you can use any other object based on requirement. To extract tabular or business card data we have to use x,y co-coordinates to get specific data (refer our previous post for this). To extract form data, Einstein API gives named entities like first_name, last_name etc from image, no need to check coordinates to extract information. Once we extracted data, we can update detail in case object.

    Let us create apex code which are required for recognizing and extracting driver license detail.

    Code File Detail:

    • EinsteinController.apxc: This class will get access token to call Einstein API. I have used salesforcecodex@gmail.com as I have registered using this email. Change this email in your code based on user created by you.
    • EinsteinFormOCR.apxc: This class will extract named entities from drive license image. We have to use Form and DL as type in parameter.
    • FormContentExtractor.apxc: This class will get image from case object. Try to upload image less then 100kb so that we can use it in Apex. For bigger size image will take longer time to process image so it will not work in all scenario.
    • FormResponse.apxc: This is response wrapper class.

    Once we call FormContentExtractor.getImageText method, we will get output in below format.

    address=123 SAMPLE STREET PHOENIX AZ, date_of_birth=09/13/1999, document_discriminator=1234567890136, endorsements=NONE, expiration_date=09/13/2021, first_name=JANE, formtype=driver LICENSE, hair=BRO, height=5'06", issue_date=09/13/2020,

    We have to updated these data in case object where image data is extracted. As these data can be different for different image type. We need some kind of mapping information to store these data in case object. So let us create a mapping object for this data and salesforce object where data need to be updated.

    We can create object with name Form Template Mapping to hold mapping information. Below fields will be added in this object.

    Field LabelField NameType
    Form FieldFormField__cText(255)
    Object FieldObjectField__cText(255)
    Form TypeFormType__cPicklist-
    Driver License
    Form 1040
    Form W-2
    Passport
    Pay Stub
    Permanent Resident Card

    Here is some sample mapping data for driver license form image.

    Driver License Form Field Mapping - SalesforceCodex

    Now we have mapped our data and object field, let us write code to updated these fields based on response and mapping.

    Line# 24 to 35 checking what response we received from image text extraction and based on that response what mapping we have in form data mapping record. If we have matching record then we will update corresponding field value.

    As this class’s method getFormData is created as InvocableMethod so that we can execute this from flow.

    Let us create flow to call method getFormData which will be available as action Extract Driver License Detail in flow.

    Steps for flow

    1. Create a recordId input variable in flow. This will get record on which page flow will be added
    2. Call action Extract Driver License Detail
    3. Show message for action result

    If you are not able to accomplished above flow step then here is link to see flow meta xml document.

    Add Flow as action button on Case object:

    Add above flow as action button and then add that button to page layout.

    Object Action Button to run Flow in Salesforce - Salesforce Codex

    5. Test Code

    Related Einstein OCR Posts

    1. Named Entity Recognition using Salesforce Einstein API
    2. Create OCR App using Salesforce Einstein OCR API
    3. Extract Text From Image using Google Cloud Vision

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleDownload S3 File in Salesforce using AWS Signature Version 4.0
    Next Article Schedule Email alerts based on Business Hours
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    View 2 Comments

    2 Comments

    1. Brijkishor on August 18, 2021 9:15 pm

      It’s just awesome.
      I need your help about one of your blog regarding presigned url.
      Can you share your contact at brij281@gmail.com

      Reply
      • Dhanik Lal Sahni on August 20, 2021 8:58 pm

        Thank You Brij. You can connect me on my linked-in or telegram profile. I am active in both applications.

        Regards
        Dhanik

        Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.