How I Built an AI Business Card Scanner for Salesforce Using Google Gemini Vision

TL;DR: Transform paper business cards into structured Salesforce Leads, Contacts, and Accounts in seconds. Built with Lightning Web Components (LWC), Apex, and Google Gemini 1.5 Flash Multimodal Vision API. Free trial and open distribution package available on GitHub.

The Problem Every Sales Rep Hates

If you've ever attended Dreamforce, a trade expo, or a networking conference, you know the drill: by the end of the day, your pocket is stuffed with 40+ paper business cards.

Back at the hotel, you have two choices:

  1. Spend two hours manually typing names, emails, titles, and messy phone numbers into Salesforce.
  2. Let the cards sit on your desk for weeks until the leads go completely cold.

Existing enterprise OCR scanners are either clunky mobile-only apps, require expensive third-party subscriptions, or struggle with multi-language cards, artistic fonts, and complex card layouts.

I wanted a solution that:

  • Works directly inside Salesforce Lightning & Salesforce Mobile App.
  • Captures cards using either the device camera or photo library.
  • Uses modern multimodal LLM vision (Google Gemini) rather than brittle legacy OCR.
  • Extracts names, emails, phones, job titles, and full addresses with 99%+ accuracy in under 3 seconds.
  • Creates verified Leads, Contacts, or Accounts in Salesforce with a single click.

Here is the technical architecture and how you can install and try it in your own org.

Solution Architecture & Flow

The application is built entirely native to Salesforce using Lightning Web Components (LWC) and Apex, communicating directly with Google AI Studio's Gemini 1.5 Flash endpoint.

[Sales Rep (Mobile/Desktop)] │ ▼ [LWC Camera Capture] ──(Client-side compression <900KB & EXIF auto-rotation) │ ▼ [Apex Controller] ──(Server-Side API Key & Permission Check) │ ▼ [Google Gemini 1.5 Flash Vision API] ──(Multimodal Structured JSON Output) │ ▼ [LWC Review & Verification Form] ──(Pre-filled fields: Name, Title, Email, Phone, Address) │ ▼ [1-Click CRM Save] ──(Insert Lead / Contact / Account WITH USER_MODE) 

3 Key Engineering Challenges & How They Were Solved

1. Mobile Camera Orientation & Payload Size

High-resolution camera uploads from modern smartphones are often 8MB–15MB in size and carry EXIF orientation metadata that causes images to rotate sideways when rendered on a canvas.

  • Client-Side Compression: High-res photos are scaled down and compressed client-side to <900KB using HTML5 Canvas before sending the base64 payload to Apex. This prevents Salesforce Apex heap size limits (6MB synchronous limit) from ever being breached.
  • Orientation Normalization: EXIF flags are read in JavaScript to ensure the business card is always upright before being sent to Gemini Vision.

2. Multi-Language & Artistic Layout Extraction

Legacy OCR engines fail when cards use vertical text, colored backgrounds, or non-English alphabets (Japanese Kanji, Chinese, Arabic, Hindi, Cyrillic).

By leveraging Google Gemini 1.5 Flash, the model doesn't just read letters—it understands layout semantics. It easily distinguishes between:

  • Direct office line vs. mobile phone.
  • Headquarters address vs. branch office.
  • Personal company email vs. generic info@ addresses.
  • Roman alphabet vs. 100+ international scripts.

3. Enterprise Security & API Key Protection

Exposing AI API keys in client-side JavaScript is a major security risk.

  • In this solution, the Google Gemini API key is stored exclusively server-side in Salesforce Hierarchy Custom Settings (Gemini_Settings__c).
  • The key is never exposed to the browser.
  • All database DML operations run WITH USER_MODE to strictly adhere to Salesforce field-level security (FLS) and sharing rules.

Try It in Your Salesforce Org

The solution is packaged as a ready-to-install package for Developer, Sandbox, and Production environments:

Quick 3-Step Setup:

  1. Install Package: Install via the installation link in the GitHub README.
  2. Assign Permission Set: Assign the Card Scanner Access permission set to your user.
  3. Add Gemini Key: Grab a free API key from Google AI Studio, open the Card Scanner tab, click the Settings Gear (⚙️), and paste your key.

You're ready to scan business cards!

What's Next & Feedback

Check out the full repository on GitHub:
⭐ Star the Repo on GitHub

If you have feedback, feature requests (e.g., custom object mapping or CPQ integration), or commercial inquiries for enterprise team rollouts, feel free to open a GitHub Issue or reach out directly to our licensing desk!