Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • The Ultimate Guide to Data Cleanup Techniques for Salesforce
    • How to Leverage Model Context Protocol (MCP) to Enhance Salesforce AI
    • Top Mistakes Developers Make in Salesforce Apex Triggers
    • Introducing Agentforce3 to Salesforce Developers
    • The Ultimate Guide to Apex Order of Execution for Developers
    • How to Handle Bulkification in Apex with Real-World Use Cases
    • How to Confidently Manage Transactions in Salesforce Apex
    • Building a Dynamic Tree Grid in Lightning Web Component
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, August 2
    • Home
    • Salesforce Platform
      • Architecture
      • Apex
      • Lightning Web Components
      • Integration
      • Flows & Automation
      • Best Practices
      • Questions
      • News
      • Books Testimonial
    • Industries
      • Artificial Intelligence
    • Hire Me
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Downloads
      • Salesforce Release Notes
      • Apex Coding Guidelines
    • About Us
      • Privacy Policy
    • Contact Us
    SalesforceCodex
    Home»Salesforce»Extract License Plate Number from Image In Salesforce

    Extract License Plate Number from Image In Salesforce

    Dhanik Lal SahniBy Dhanik Lal SahniJune 17, 2020Updated:December 26, 20242 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Extract License Plate Number from Image In Salesforce
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Last week I got a request about extracting the vehicle license plate numbers. Requester wanted to extract the license plate number from the image. I was not sure that we have a specific API for this request. After analysis, I found License Plate Number APIs which can extract plate numbers from images.

    To extract the license plate number from the image in Salesforce, we have to complete the below steps

    1. Get the test credential from RapidAPI
    2. Create Apex Class to extract Plate Number from the image
    3. Call Apex class from Flow
    4. Add button on page layout and call flow

    1. Get the test credential from RapidAPI

    Create an account in RapidAPI.com to test License Plate Recognition API. Once the account is created, go to https://rapidapi.com/macgyverapi/api/license-plate-recognition1 and get a test credential for this API.

    2. Create Apex Class to extract Plate Number from image

    Once test account and API credential are created, let us create apex class which will be extract license plate number from image.

    API Url : https://macgyverapi-license-plate-recognition-v1.p.rapidapi.com/

    Above API will need image url to process so we have to get url for our uploaded image in Salesforce record. Sample request for this API is below

    {
        "id": "3X5D3d2k",
        "key": "free",
        "data": {
            "image_url": "https://storage.googleapis.com/marketing-files/program-markdown-assets/license-detection/license-plate.jpg",
            "country": "us",
            "numberCandidates": 2
        }
    }

    External Url for Image:

    We can use ContentDistribution object for getting image url from uploaded image. We can create public image link when we upload file. Create trigger for creating public link.

    trigger ContentVersionExternalLink on ContentVersion (after insert) {
    	ContentTriggerHandler.createPublicLinkForFile(trigger.new);
    }

    ContentTriggerHandler class will help in creating public link for uploaded image. This class will be called from ContentVersionExternalLink trigger.

    public class ContentTriggerHandler {
        public static void createPublicLinkForFile(List<ContentVersion> contentVersions){
            ContentDistribution[] distributionsToInsert = new List<ContentDistribution>();
            Set<Id> contentDocId = new Set<Id>();
            for(ContentVersion objContentVersion : contentVersions){
                contentDocId.add(objContentVersion.ContentDocumentId);
            }
            for(ContentVersion objContentVersion : contentVersions){
               distributionsToInsert.add(createContentDistribution(objContentVersion.Id));
            }
            insert distributionsToInsert;
        }
        
        public static ContentDistribution createContentDistribution(Id contentVersionId){
            ContentDistribution newDist = new ContentDistribution();
            newDist.ContentVersionId = contentVersionId;
            newDist.Name = 'External Link';
            newDist.PreferencesNotifyOnVisit = false;
            newDist.PreferencesAllowViewInBrowser = true;
            return newDist;
        }
    }

    We also have to make uploaded file visible using ContentDocumentLink. Create trigger for this like below code.

    trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
        for(ContentDocumentLink l:Trigger.new) {
            l.Visibility='AllUsers';
        }
    }

    Now we will get public downloadable link of uploaded image. Let us create apex class which will extract plate number.

    Complete Apex Code:

    Above code will also update vehicle license plate number in case object. Create Plate Number field in case object to store extracted plate number.

    Note: Add API url in remote site setting or you can use named credential to avoid this.

    3. Call Apex class from Flow

    After apex class created, we have to call this apex class from flow or lightning component. I have used flow to use as standard feature instead of custom code.

    Here is complete flow process.

    Variables :

    Create two variables recordId and varRecordId.

    This variable will hold value when record id passed from record page to flow.

    Assignment Logic :

    Create assignment logic to assign value from recordId to varRecordId. recordId is passed from record page.

    Action Method :

    Call apex class from action flow. Pass varRecordId to apex method. @InvocableMethod annotation is required for calling any apex method from flow.

    4. Add button on page layout and call flow

    Add a new action button in case object and then put this button on page layout. This button will call flow to update plate number in field.

    Test Page;

    References:

    https://rapidapi.com/macgyverapi/api/license-plate-recognition1

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_what_is_apex.htm

    apex apex rest api flow rest api
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleGenerate own code for Apex using Salesforce CLI
    Next Article Create OCR App using Salesforce Einstein OCR API
    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 Sahni6 Mins Read

    How to Leverage Model Context Protocol (MCP) to Enhance Salesforce AI

    July 28, 2025
    By Dhanik Lal Sahni7 Mins Read

    Top Mistakes Developers Make in Salesforce Apex Triggers

    July 25, 2025
    By Dhanik Lal Sahni14 Mins Read

    The Ultimate Guide to Apex Order of Execution for Developers

    July 20, 2025
    View 2 Comments

    2 Comments

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

    2. Dhanik Lal Sahni on December 7, 2020 6:21 pm

      Hey Smriti,

      Looks like this API is down. Their website is also down, looks like they have stop their service.

      I will write blog with some other API for this use case.

      Thank You for letting me know.

      Dhanik

      Reply
    Leave A Reply Cancel Reply

    Ranked #1 Salesforce Developer Blog by SalesforceBen.com
    SFBenTopDeveloper
    Ranked #4 Salesforce Developer Blog by ApexHours.com
    ApexHoursTopDevelopers
    Categories
    Archives
    Tags
    apex (116) apex best practices (5) apex code best practice (10) apex code optimization (6) Apex logging (4) apex rest (11) apex trigger best practices (6) architecture (22) Asynchronous apex (9) AWS (5) batch apex (10) best code practice (4) code optimization (9) custom metadata types (5) design principle (9) flow (16) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (66) lightning-combobox (5) lightning-datatable (10) lightning component (32) Lightning web component (64) lwc (53) named credential (8) news (4) optimize apex (5) optimize apex code (6) optimize apex trigger (5) Permission set (4) Queueable (9) queueable apex (4) rest api (23) salesforce (150) salesforce apex (52) salesforce api integration (5) Salesforce Interview Question (5) 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

    MailChimp

    Expert Salesforce Developer and Architect
    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • The Ultimate Guide to Data Cleanup Techniques for Salesforce
    • How to Leverage Model Context Protocol (MCP) to Enhance Salesforce AI
    • Top Mistakes Developers Make in Salesforce Apex Triggers
    • Introducing Agentforce3 to Salesforce Developers
    • The Ultimate Guide to Apex Order of Execution for Developers
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 10 Salesforce CRM Trends to Watch in 2025 July 18, 2025
    • Discover the Top 10 Salesforce AppExchange Apps to Boost Productivity July 10, 2025
    • 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
    Archives
    Categories
    Tags
    apex (116) apex best practices (5) apex code best practice (10) apex code optimization (6) Apex logging (4) apex rest (11) apex trigger best practices (6) architecture (22) Asynchronous apex (9) AWS (5) batch apex (10) best code practice (4) code optimization (9) custom metadata types (5) design principle (9) flow (16) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (66) lightning-combobox (5) lightning-datatable (10) lightning component (32) Lightning web component (64) lwc (53) named credential (8) news (4) optimize apex (5) optimize apex code (6) optimize apex trigger (5) Permission set (4) Queueable (9) queueable apex (4) rest api (23) salesforce (150) salesforce apex (52) salesforce api integration (5) Salesforce Interview Question (5) 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.