Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • 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
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, June 21
    • 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»Extract Text From Image using Google Cloud Vision

    Extract Text From Image using Google Cloud Vision

    Dhanik Lal SahniBy Dhanik Lal SahniApril 30, 2020Updated:June 11, 202315 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Extract Text From Image using Google Cloud Vision
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Recently I got request from one of my blog member for extracting text from image which is uploaded in Salesforce record’s attachment. So i have analyzed some APIs which has similar capability.

    There are various tool and APIs available for extracting text from images. Here are some of them which are popular in market

    1. Google Cloud Vision
    2. Microsoft Computer Vision
    3. Taggun
    4. Cloudmersive

    For this blog, i have used Google Cloud Vision to extract text from image.  This OCR (Optical Character Recognition) API has special feature to recognize logo as well.

    The Google Cloud Vision API enables developers to understand the content of an image by encapsulating powerful machine learning models in an easy to use REST API. You can build metadata on your image catalog, moderate offensive content, or enable new marketing scenarios through image sentiment analysis.

    Let us see steps required to extract text from image.

    1. Enable Google Cloud Vision API
    2. Create Apex class to extract text from image
    3. Create lightning component to extract image
    4. Add lightning component as button on record page

    1. Enable Google Cloud Vision API

    First we have to enable Google Cloud Vision API and create API key for authentication purpose.  Below steps can be performed to get API key.

    1. Create user in Google cloud at https://console.developers.google.com . We can also use any existing gmail user.
    2. Create project in Google Console
    3. Once project is created, go to API library at https://console.developers.google.com/apis/library. Select Google Cloud Vision API and enable it.
    4. Create Credential (API Key) for API to be used.
    5. Add https://vision.googleapis.com in Salesforce’s remote site setting

    2. Create Apex class to extract text from image

    We have to create apex class which will use Google Cloud Vision API and extract text from image. You can check API request and response detail at https://cloud.google.com/vision/docs/reference/rest.

    ImageService apex class will extract text. We should create separate request and response class for passing and getting data as JSON.

    3. Create lightning component to extract image

    In step 2, We have created image service class which will extract text from given image’s blob data. In this step we will get image file content and pass content to above mentioned class.

    ImageServiceController class will be used to get all image files on which processing will be done for extracting text.


    Let us create lightning component to consume above ImageServiceController. When image is successful extracted, this component show ‘Text extracted from image. Check file record detail section’.

    4. Add lightning component as button on record page

    Add lightning component as button or component in your record page.  If you have added that as button, when you click button it will call component and extract text from image. After you got message Text extracted from image. Check file record detail section, you can go to image file and check extracted texts.

    Demo

    References:

    https://cloud.google.com/vision/docs/reference/rest

    Related Posts

    1. Named Entity Recognition using Salesforce Einstein API
    2. Extract Driver License Detail from Image using Einstein API
    3. Create OCR App using Salesforce Einstein OCR API
    apex cloud vision api google google cloud vision lightning ocr ocr api salesforce
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleExtend lightning-datatable with file upload element in Lightning Web Component
    Next Article Reusable Compare Element in Lightning Web Component
    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 Sahni9 Mins Read

    10 Salesforce Chrome Extensions to Boost Your Productivity

    June 1, 2025
    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
    View 15 Comments

    15 Comments

    1. Dhanik Lal Sahni on May 3, 2020 8:00 am

      Thank You Abhinav. Let me know, if you need our help.

      Reply
    2. Nilesh Borse on May 18, 2020 6:16 pm

      I am getting following error:
      This API method requires billing to be enabled. Please enable billing on project #659325175485 by visiting https://console.developers.google.com/billing/enable?project=659325175485 then retry. If you enabled billing for this project recently, wait a few minutes for the action to propagate to our systems and retry

      Reply
      • Dhanik Lal Sahni on May 19, 2020 2:22 pm

        Hello Nilesh,

        Looks like billing is not set for your vision project. Please check this video for that support https://www.youtube.com/watch?v=uINleRduCWM.
        You can also log support ticket in google console to resolve this issue.

        Thank You,
        Dhanik

        Reply
    3. Vineet Bhagchandani on May 29, 2020 2:08 pm

      Hello Dhanik,
      Great Post and Very Useful
      One thing I need to know is how we can automatically parse the response to create a Lead Record or Contact Record. The Details are stored as the text file so how to appropriately parse the data to have accurate data?

      Your help is much appreciated

      Thanks in Advance

      Reply
      • Dhanik Lal Sahni on May 31, 2020 12:40 am

        Hello Vineet,

        You can use BoundingPoly (text location coordinates) for each text section. Check link https://cloud.google.com/vision/docs/handwritinghttps://cloud.google.com/vision/docs/handwriting
        Thank You,
        Dhanik

        Reply
    4. Vineet Bhagchandani on May 29, 2020 2:39 pm

      Or I mean to say how to identify the data like this is the name and this is address etc

      Reply
      • Dhanik Lal Sahni on May 31, 2020 12:42 am

        Hello Vineet,
        You can use BoundingPoly (text location coordinates) for each text section.

        Thank You,
        Dhanik

        Reply
    5. Pingback: Create OCR App using Salesforce Einstein OCR API | SalesforceCodex

    6. Sandeep on October 24, 2020 11:37 pm

      Hi Dhanik, Thank you for sharing this wonderful post. I have a query regarding component attribute “recordId”. Where does this attribute get its value from?

      Thanks, Sandeep

      Reply
      • Dhanik Lal Sahni on October 28, 2020 6:34 pm

        value for recordid is populated by aura framework for current record. see documentation for this.

        Thank you,
        Dhanik

        Reply
    7. Rahul S on July 1, 2021 10:41 am

      Hello Dhanik,

      Great post, one doubt will the same code implementation work for getting a text from PDF file if we query the pdf data in “List docs=[SELECT ContentDocumentId FROM ContentDocumentLink
      WHERE ContentDocument.FileType=’JPG’ and LinkedEntityId =:record];”

      and use “https://vision.googleapis.com/v1/files:asyncBatchAnnotate?key=your-api-key” as end point URL.

      Please suggest.

      Thanks & Regards,
      Rahul S

      Reply
      • Dhanik Lal Sahni on July 3, 2021 1:28 pm

        Hello Rahul,

        Concept will be same for PDF also. You have to change some request attribute. Please sample request at https://cloud.google.com/vision/docs/pdf.

        Thank You,
        Dhanik

        Reply
    8. Jonathan Q on August 17, 2023 12:00 pm

      I’m getting the error, “Variable does not exist” for Extracted_Text__c and Is_Extracted__c. Under what object are we supposed to create these variables?

      Reply
      • Dhanik Lal Sahni on August 26, 2023 6:34 pm

        Hello Jonathan,
        It will be created in ContentVersion object.
        Thank You,
        Dhanik

        Reply
    9. Pingback: Ultimate Guide to Integrate Stripe with Salesforce CRM

    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • 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
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins June 5, 2025
    • 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
    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 analysis (3) code optimization (8) custom metadata types (5) design principle (9) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (65) lightning-combobox (5) lightning-datatable (10) lightning component (31) Lightning web component (63) lwc (52) named credential (8) news (4) optimize apex code (4) optimize apex trigger (3) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (142) salesforce apex (47) 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.