About the Client
The client is a sales-driven organization that receives a large volume of customer purchase orders and invoices by email. Sales representatives forward these emails to a central mailbox for processing, and the company uses Salesforce to manage customers, products and revenue operations.
The Challenge
Turning customer purchase orders into sales orders was slow and manual.
Orders in Every Format
Sales orders arrived across many emails, with attachments in different formats.
Manual Data Entry
Order details were typed into Salesforce by hand, causing delays and errors.
Unclear Attribution
It was hard to tell which salesperson had forwarded each order.
No Central Tracking
Inbound emails and attachments weren’t tracked in one place.
Unreadable or Missing Attachments
Problem documents created bottlenecks in order processing.
Mapping Risks
Products could be mapped incorrectly, and some customer accounts didn’t exist yet in Salesforce.
The Solution
LST Consultancy built a Salesforce-native email-to-sales order automation framework using Salesforce Email Services, Nanonets OCR, Apex and Lightning Web Components.
Order inbox
Forwarded by sales reps
- PO-88412.pdfFrom: rep aliasReceived
- Order.xlsxVia GraphConverted
- No attachmentBody to PDFConverted
- Scan_0312.jpgLow qualityManual
Email Services + Apex + Nanonets OCR
- Header parsing
- Queueable Apex
- JSON extract
- Retries
Salesforce
Review, approve, create
- Email Storage recordFiles linked, nothing lost
- Split-screen reviewDocument beside the data
- Sales Order + linesCreated on approval
- SalespersonAttributed from headers
Email Ingestion and Storage
- Salesforce Email Services provides a single inbound email address.
- An Apex Inbound Email Handler captures each email’s metadata, body, headers and attachments.
- A custom Email Storage object tracks every inbound email.
- Attachments are stored securely as Salesforce Files, linked to their email record.
Salesperson Identification
- The forwarding salesperson is identified from the email headers.
- Admins can map forwarding aliases to Salesforce users.
- Every Sales Order is attributed to the right person.
OCR Processing and Data Extraction
- Attachments are sent to Nanonets OCR in the background using Queueable Apex.
- Order header and product line data is extracted in JSON format.
- The extracted data is saved against the email record for review.
Review and Approval Screen
- A split-screen Lightning Web Component shows the original document on the left and the extracted fields and line items on the right.
- Reviewers can Approve (creating the Sales Order), Reject, Preview or Create Account.
Sales Order Creation
- Approved records automatically create Sales Orders and Sales Order Line Items.
- The system checks that the customer account exists and that products map correctly.
- If a customer is missing, reviewers are guided through creating the account.
Exception Handling
- Emails without attachments are converted into PDFs from the email body.
- A manual data entry flow handles unreadable documents.
- Microsoft Graph API converts Word and Excel files into PDFs for processing.
How We Delivered It
We delivered the solution in five phases.
Requirement Analysis
We captured the inbound email scenarios, OCR scope and approval workflows.
Solution Design
We designed the email ingestion architecture, the data model and the OCR integration.
Development
We built the Apex Inbound Email Handler, the Email Storage object, the OCR integration with Queueable Apex, the review and approval screen, and the Microsoft Graph integration.
Testing
We validated OCR accuracy, salesperson mapping, error scenarios and bulk email processing.
Deployment
We rolled out the solution with user training and monitoring.
Technical highlights
- Salesforce Email Services
- Apex Inbound Email Handler
- Queueable Apex
- Nanonets OCR REST API
- Microsoft Graph API
- Lightning Web Components
- Custom metadata for API keys
Obstacles We Overcame
Automating orders from a shared inbox raised five issues. Here’s how we handled each one.
Identifying the correct salesperson
- Challenge
- Forwarded emails didn’t clearly show which salesperson sent each order.
- How we solved it
- Header-based logic with admin mapping of aliases to users.
OCR failures
- Challenge
- OCR calls could fail and leave orders unprocessed.
- How we solved it
- A retry mechanism, with manual entry as a fallback.
Unreadable documents
- Challenge
- Some attachments couldn’t be read at all.
- How we solved it
- Manual PDF generation and data entry.
Product mismatches
- Challenge
- Extracted products didn’t always match Salesforce products.
- How we solved it
- Product validation and a mapping interface.
Performance under load
- Challenge
- Hundreds of emails a day could slow processing.
- How we solved it
- Asynchronous processing and batching.
The Results
The automation made order intake accurate, traceable and fast.
By the Numbers
- 90%+
- OCR accuracy on standard invoice formats
- 500+
- emails a day handled by a scalable solution
What Changed
- No lost attachmentsCentralized email storage keeps every file linked to its email.
- Less manual entrySignificantly less manual order entry.
- Faster turnaroundFrom email receipt to Sales Order creation.
- Clear accountabilityEvery order is attributed to the right salesperson.
Key Takeaways

Plan for exceptions from the start
Email-driven automation only works with strong handling for missing, unreadable and unusual documents.
Keep a human in the loop for financial documents
A quick review step catches the rare OCR misread before it becomes an order.
Email headers hold the answers
Header analysis is essential for knowing who forwarded each order.
Process asynchronously
Background processing keeps the system fast at hundreds of emails a day.