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.
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: –
Hi @Amit : Thanks for the code. But i guess there
I guess here? Complete it.
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)
Check your inner class and see if the variable is present and if the variable is present then make it public.
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.
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
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.
No, You can not.
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 ?
yes you can do that but for this you need to come up with a solution with your architect.