Skip to main content
← Back to Case Studies
Case StudySoftware / SaaS

Salesforce lead qualification with an AI scoring layer

Client · A B2B SaaS company
SalesforceSalesforceApexOpenAILead Qualification
Salesforce lead qualification with an AI scoring layer
24–48 h → under 15 min
Hot-lead response time
Owner-reported

Owner-reported: these figures are reported by me, not independently audited. Client names are withheld.

Stack
SalesforceApex triggersNode.jsOpenAI API (GPT-4)Clearbit
01 / Problem

The Challenge

A sales team had good leads and good data, and still answered its best prospects a day or two late. The data sat in Salesforce; what was missing was anything that read it before a person had to.

The company's sales team qualified every inbound lead by hand. Each rep opened lead records one at a time, read the form submission, looked up the company and made a judgement call. With a steady daily flow of inbound leads, that review took a large part of every rep's day, and it happened in whatever order the leads arrived.

The cost showed up in response time. Follow-up on a lead often came 24 to 48 hours after the prospect filled in the form. For inbound B2B leads, that is long enough for interest to cool or for a competitor to answer first. Hot leads waited in the same queue as poor fits, because nothing told the reps which was which.

The frustrating part was that the information was already there. Salesforce held rich data on every lead, but there was no intelligence layer on top of it: no ranking, no summary, nothing that turned a record into a decision.

Constraints

  • Salesforce stays the system of record. Reps already worked in the CRM. The answer had to arrive inside it, not in a separate tool.
  • Platform rules. Salesforce does not allow an external callout in the middle of a trigger's transaction, so any call to an AI model had to run outside the save that created the lead.
  • Reps keep the decision. The system had to make the judgement call faster and better informed, not take it away from the people who own the relationship.
02 / Approach

The Solution

I have worked on Salesforce since 2018, mostly on Flows, Apex and REST integrations with outside systems. This project combined those with a language model: Salesforce supplies the context, the model reads it the way a rep would, and the result goes back to where the reps already work.

Architecture

The integration has three layers:

  1. Salesforce (Apex triggers). When a lead is created, an Apex trigger collects every field the decision depends on: company size, industry, job title, website and the free-text form message.
  2. A Node.js middleware layer. The trigger hands the lead to a small middleware service. The middleware enriches it with Clearbit company data and builds the request for the model. Keeping this layer outside the org means the prompt and the external API calls can change without a Salesforce deployment, and API keys for outside services don't live in Apex.
  3. The model (OpenAI GPT-4). The enriched lead goes to a custom prompt, engineered to return a structured qualification score rather than free text, so the result can be stored and sorted like any other field.

What I built

  • The Apex trigger on lead creation that gathers the qualification inputs and hands them off asynchronously, within Salesforce's callout rules.
  • The Node.js middleware that enriches each lead with Clearbit data and calls the OpenAI API.
  • The qualification prompt, designed around a fixed output structure so every lead is scored the same way, whichever rep would have reviewed it.
  • The round trip back into Salesforce, so the score is available on the lead and the team can work from a ranked list instead of an unsorted queue.

Why these decisions

  • Score on arrival, not in a batch. A nightly scoring job would still leave hot leads waiting until morning. Scoring every lead the moment it enters the CRM is what makes a same-hour response possible.
  • Structured output over prose. A summary is useful to read; a structured score is useful to sort, filter and report on. The prompt was built for the second.
  • Enrichment before judgement. A form submission alone often says little about the company behind it. Adding company data first gives the model, and the rep, the context a rep would otherwise look up by hand.
03 / Impact

Results

Owner-reported result after go-live:

  • Hot-lead response time: 24–48 hours → under 15 minutes.

Alongside that number, the team saw changes in how the day works:

  • Manual qualification time dropped sharply. Reps no longer read every record from scratch; they start from a score, and spend the saved time on the conversations.
  • More of the hot leads turned into meetings, because they were contacted while the interest was still fresh.
  • Rep productivity is where the client saw the saving: the hours handed back to the sales team.

What the team can do now that it couldn't before: see which inbound leads matter the moment they arrive, and answer them the same hour instead of the next day.

Stack

  • Salesforce: the system of record, where leads arrive and where the score ends up.
  • Apex triggers: start the qualification when a lead is created.
  • Node.js: the middleware layer for enrichment and the model call.
  • Clearbit: company data that enriches each lead before scoring.
  • OpenAI API (GPT-4): reads the enriched lead and returns the structured qualification score.

What I learned

  • The CRM already knew enough. Most of the value came from reading data the company already had, quickly and consistently, not from collecting more.
  • Put the AI where the work happens. A score in a separate dashboard would have been one more tab. A score on the lead, in Salesforce, changed what reps saw first.
  • Design the output before the prompt. Deciding what the score must look like, and how it will be used, made the prompt easier to write and the results easier to trust.

What I'd do next

Today the same pattern can run closer to the platform: Agentforce and Salesforce's own AI features can take over parts of the middleware's job, and the scored leads could route themselves to the right rep through a Flow, so the first touch is assigned as well as prioritised.

Share
Work with me
Have a problem like this one?

Tell me about the process that's slowing your team down. I'll tell you honestly whether automation, Salesforce or an AI agent is the right fix.