TwinStack built two Claude agents that load daily grain bid prices from GrainCorp and Bunge into AgVantage Commodities' Salesforce org, replacing manual entry. Both agents run in production and have processed thousands of bids.
At a glance
| Client | AgVantage Commodities, Australia |
|---|---|
| Industry | Agricultural commodity trading |
| Built | Mainly August 2026, then moved from sandbox to production |
| Claude products | Claude agents with reusable skills |
| Integrations | Salesforce (custom Apex REST service), buyer websites, Microsoft 365 and Gmail |
| Crops covered | Wheat, barley, canola, lentil, chickpea, sorghum |
The challenge
AgVantage tracks grain bids in Salesforce as Bid__c records. These feed bid-offer combinations, available stock and the dashboards traders use to compare bids with offers. Buyers such as GrainCorp and Bunge publish their daily prices as PDF bid sheets, not as data feeds, and these sheets are hard to turn into records:
- Layouts vary. Some sheets list sites in rows, but the SA and WA wheat sheets are transposed. Crop years are stacked in blocks, and Fixed and Multi Grade tables sit side by side.
- Names don't match Salesforce. Buyer site, grade and commodity names rarely match the org's picklist values and site records.
- Volume is high. Each run covers several regions and commodities.
- Errors are costly. A price under the wrong site, grade or crop year distorts what traders see.
The goal was a hands-off pipeline that takes a buyer's published sheet, produces correct Salesforce records and tells AgVantage what happened.
The solution
TwinStack built one agent per buyer. Each runs the same four stages, and each stage is a reusable Claude skill:
- Fetch. The agent logs in to the buyer's site (Selenium and Chrome) and downloads the current bid-sheet PDF for every region. The GrainCorp agent covers QLD, NNSW, SNSW, VIC, SA and WA. The Bunge agent covers NSW Northern, NSW Southern and QLD Southern.
- Convert. It extracts each PDF table into a Salesforce-ready CSV, then normalizes sites, grades and commodities. GrainCorp and Bunge have sibling skills because each buyer needs its own rules. Bunge's skill applies nine normalization rules, including a 16-entry lookup of site names.
- Upload. It posts the CSV to BidCsvUploadRestService, a custom Apex REST service, which returns a result for every row: created, updated, skipped or failed.
- Report. It emails AgVantage a colour-coded HTML report of the run, built in Apex.
How Claude is used
Claude does more than run scripts. It applies judgement at the points where a mistake would be expensive:
- It checks rendered pages to confirm each price sits under the right site, grade and crop year.
- It uses a Multi Grade price only when no fixed bid exists.
- When the same site, grade and crop year appear in both the Fixed-Grade and Delivered tables, it keeps them apart with a -DEL suffix on the Delivered row's ID.
- It never guesses ambiguous rows, such as POA prices or unclear crop years. It flags them with options for resolving them and writes them to a review folder instead of uploading them.
- After each upload, it reads the response and explains any failures in plain language.
Implementation highlights
Coordinate-based text extraction (pdftotext with character-position column bucketing) proved more reliable than image-only OCR, because position carries the meaning in these sheets. On the Salesforce side, the REST service cleans site names, maps grade codes through aliases, and resolves restricted picklist values dynamically instead of hardcoding them.
| Challenge | How it was solved |
|---|---|
| Side-by-side and stacked tables merged on one page | Recursive block and band segmentation with a gap threshold calibrated per page |
| Wrong crop year on multi-year sheets | Crop year assigned per column |
| Extractor exited cleanly with zero rows on Bunge two-crop-year grids | pdfplumber fallback, plus per-page error handling, partial writes, new exit codes and per-row validation |
| Debug logs hit Salesforce's 20 MB cap during uploads | Removed inner-loop debug calls |
| Report colours misaligned with columns | Fixed column alignment in the Apex report builder |
| Moving to production, and Bunge's mail from Gmail to Microsoft 365 | Both agents migrated, with a check that the upload URL targets production |
Results
- Trader-facing bid data no longer depends on someone retyping PDF tables.
- Every run ends with an email showing which rows were created, updated, skipped or failed.
- Normalization rules and the review path keep ambiguous or mismatched rows out of the live org.
- The fetch, convert, upload and report skills can be reused for more buyers.
Lessons learned
- Position carries meaning in tabular PDFs, so coordinate-based extraction with visual spot-checks beats OCR alone.
- Putting buyer-specific rules in a sibling skill kept the GrainCorp logic stable while Bunge's evolved.
- Flagging ambiguity for review is cheaper than correcting wrong bids after upload.
Want Claude working inside your business?
TwinStack builds Claude agents, skills and integrations that fit how your team already works, with people kept in the loop where judgement matters.
Talk to Us