Create Contact/Lead from the business card using Einstein OCR API

Hey Everyone,

Welcome back 🙂 , In this blog post, we are going to learn how to read the details from the Business Card or Visiting card and then create either lead/contact or any custom object record.

To read the business card we need to send the task body parameters with contact as a value.

Before we get started, if you have not gone through with the earlier blog post as those are related to this blog post.

  1. JWT Authentication
  2. Extract text from an image using Einstein OCR API

Let’s start with the development. Fist let’s check how the UI will look like.

Create a Lightning Web Component

So, for the User Interface, we are going to use the lightning web component. Create a Lightning Web Component and you can name it anything. Here is the code for the same

In the above component, we are using FileReader to read the file content as base64 format. You can read more about FileReader here

Modify Our Existing Apex Class “EinsteinOCRService

In our existing class, we have added a new method which is readBusinessCardBase64 which accepts 2 parameters sampleBusinessCard in base64 format and objectName the name of the object where you wanted to insert the record.

Find the complete code here

Remember, we discuss the new body parameter value. Let’s make the change in another existing class “EinsteinAPIService“. Here is the updated code.

Let’s check out the demo

Thanks for reading 🙂 😉

#SFDCPanther #AskPanther

Resources: –

  1. https://metamind.readme.io/docs/detect-text-in-business-cards
  2. JWT Authentication
  3. Extract text from an image using Einstein OCR API
  4. Full Code

Amit Singh
Amit Singh

Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion

Articles: 299

13 Comments

  1. Hi Amith,
    I am getting “variable does not exist: attributes at line 18” error in the EinsteinOCRService class. In the below method.
    AuraResponseWrapper readBusinessCardBase64(String sampleBusinessCard, String objectName)

    • you have to declare attributes variable of attributewrapper and in attributewrapper there should be a variable named tag to be declared as well

      • If it’s a requirement for you, you can use that. I did not have a requirement so I did not use it. This is just a sample code that you can take and then make the changes accordingly.

  2. after inserting a record in lead from an image, if we try to insert a record in contact for same image, it is showing error.
    why?

    • You have to modify the class in order to make it work. The code I have used is well fitted for Lead object. You need to check the error and then make the adjustment accordingly.

      • i got it , the problem was duplicate lead/contact rule was activated in duplicate rule settings in setup

  3. can we detect and create records if the image/pdf has both unstructured text and tables as well like in invoices or bills or bank statements for which the attribute tag names created from the json response cannot be matched as it predicts ‘OTHER’ for every text detected.

  4. Hi Amit,

    Can we have this setup automated for getting the PDF’s in bulk from Snowflake and doing the OCR to create new Records ?

Comments are closed.

Discover more from Panther Schools

Subscribe now to keep reading and get access to the full archive.

Continue reading