Course 3.4 · Curriculum 2026.1
Calling a model from Apex safely
The tier most teams reach for, built properly. Callout budget, structured output, per-user identity, retries, and the writes that must be validated first.
- Estimated effort
- 8 hr
- Lessons
- 66
- Modules
- 10
- Material
- 8 hr
Estimated effort is the sum of the lesson and lab times in this version of the course. It is not video runtime, which is lower.
Canadian dollars. One learner, lifetime access to this course version. Tax extra.
1 lesson free to preview
This course does not issue a certificate on its own. It counts toward the paths listed below, and those do.
01What you will learn
8 capabilities, stated as things you can do
Each one is what you should be able to do at the end, not what the course covers. If an outcome is not testable, it is not an outcome.
- Call a model from Apex inside the callout budget, with a timeout chosen rather than defaulted.
- Request structured output and parse it without trusting the shape.
- Carry the calling user’s identity through the call, with no shared service account.
- Fail closed when identity cannot be established, rather than guessing.
- Handle rate limits, retries and partial responses without duplicating writes.
- Keep the model call out of the synchronous transaction when the user is waiting.
- Test a model call deterministically with a mock.
- Log a call so a bad answer three weeks ago can still be explained.
02Curriculum
10 modules, 66 lessons
Every lesson shows its length and its type. A SCORM lesson looks like any other lesson, which is the point of ingesting packages rather than linking out to them.
10 modules · 66 lessons · 8 hr of material
The 120-second cumulative callout budget per transaction is not a footnote. It is the reason the timeouts in this course are 25, 45, 60 and never 120.
- VideoWhere the model lives: platform models and external endpointsPreview6 min
- VideoThe 120-second cumulative callout budget per transaction6 min
- VideoTimeouts of 25, 45 and 60 seconds, and why never 1206 min
- VideoThe 90-second wall-clock stop, on top of the callout budget6 min
- ReadingStreaming, and why you usually cannot use it here5 min
- VideoCost per call, and instrumenting it from day one6 min
- LabLab: make your first governed model call14 min
A custom setting field was rejected for a precise reason: in an unmanaged org it is readable by any API-enabled user. The key lives in a named credential’s password instead.
- VideoWhy a custom setting field was rejected: readable by any API-enabled user6 min
- VideoThe named credential’s password, merged into a header6 min
- VideoProving the key never becomes an Apex value6 min
- VideoThe key that cannot be logged, cannot land in an exception, cannot be echoed back6 min
- ReadingRedeploying a named credential from source control blanks its password5 min
- VideoThe incident: an API key in a custom setting field, and what it cost5 min
- LabLab: wire a callout through a named credential and grep the logs for the key14 min
Nothing derived from a provider error body reaches the caller. Only a status code and a clean enum. Then a test that proves it, twice.
- VideoNothing derived from a provider error body reaches the caller6 min
- VideoA clean enum, and a status code. Nothing else.6 min
- VideoThe test: an error body containing a fake key6 min
- VideoThe sweep: zero hits for a key fragment anywhere in the table6 min
- ReadingWriting the test before the feature, for this one exception5 min
- LabLab: prove a secret does not leak, twice14 min
A model returns text. Everything downstream needs a type, and everything upstream can lie about the shape.
- VideoAsking for structure, and why you still cannot trust it6 min
- VideoParsing defensively: missing fields, extra fields, wrong types6 min
- VideoChecking the block reason before you read anything else6 min
- VideoEmpty candidates, a non-stop finish reason, and null content6 min
- VideoApex classes as the contract, and deserialising into them6 min
- VideoRejecting a response rather than storing a guess6 min
- LabLab: parse and reject three malformed responses14 min
No person-level data leaves the org. And the project must be on a paid tier before real data is sent, because a free tier may use your prompts to improve its product.
- VideoNo person-level data leaves the org6 min
- VideoCompany name, city and country. Nothing else.6 min
- VideoContact names are card-only, never prompt input6 min
- VideoThe free-tier retention rule: a paid tier before real data goes out6 min
- ReadingShipping the feature switched off rather than shipping the risk5 min
- LabLab: strip a payload down to what is actually allowed14 min
The rule that makes this safe: the platform enforces the permissions, so we never reimplement them. Every call carries the calling user.
- VideoPer-user identity, and no shared service accountThe platform already knows what this user may see. A second copy of that logic is a second copy that can be wrong.6 min
- VideoNever source a token from application-scoped stateAn application-scoped key is shared by every user of the agent, so a token stored there runs one person’s conversation as another.6 min
- VideoFailing closed when identity cannot be established6 min
- VideoLocal development fallback, gated behind a flag nothing in the cloud can trip6 min
- ReadingWhy the platform’s own permission model is the one to trust5 min
- LabLab: prove the call runs under the caller, not an admin14 min
Three rules that outlive the code that first wrote them: cache what should not be recomputed, validate what gets written, and never let a human edit an AI opinion.
- VideoA cache rule that is the cost control, previewed here and built in full in course 3.76 min
- VideoModel output is validated before it is written6 min
- VideoProvenance defaults to the weaker claim6 min
- VideoUsers cannot edit AI advice, because the object is read-only6 min
- ReadingWhy a read-only object is a design decision, not a missing feature5 min
- LabLab: make an AI advice object read-only and prove it14 min
Asynchrony, retries, testing and logging. The four things that decide whether this is supportable at month six.
- VideoGetting the call off the synchronous transaction6 min
- VideoRate limits, backoff, and not duplicating a write on retry6 min
- VideoDeterministic tests for a non-deterministic call6 min
- VideoLogging a model call so a bad answer is explainable later6 min
- VideoWhat actually goes in the log, and what never does5 min
- LabLab: add retries and a mock-backed test suite14 min
- ReadingA logging checklist before you ship5 min
The failure that forced the architecture. A free-tier key capped the model at 20 requests a day, so the first full run analysed 2 of 256 records and stamped 250 with an error.
- VideoThe free tier caps the model at 20 requests per project per day6 min
- VideoThe first full run: 2 of 256 records analysed, 250 stamped with an error6 min
- VideoWhy Apex cannot sleep and cannot honour a retry-after6 min
- VideoThe 120-second budget is a wall a daily quota does not care about6 min
- ReadingReading a rate-limit payload for what it actually says5 min
- LabLab: reproduce the quota wall against a stub endpoint14 min
- VideoWhen this becomes a tier-three decision, not a tier-two one5 min
The worker keeps prompts, inputs and the cache rule in Apex so the two paths can never drift, and adds everything Apex structurally cannot do: pacing, backoff, batching, a heartbeat.
- VideoKeeping prompts, inputs and the cache rule in Apex, so the two paths cannot drift6 min
- VideoPacing requests, and backing off exponentially6 min
- VideoStopping on a per-day quota bucket, not a per-call one6 min
- VideoPosting results back in batches, so a crash loses nothing6 min
- VideoA heartbeat, and a watchdog that emails when it goes quiet6 min
- LabLab: write a unit test for the quota classifier against a real payload14 min
- QuizCheck: calling a model from Apex21 min
03Before you start
What you need first
Assumed knowledge and setup
- Courses 2.1 and 3.1. The callout budget from 2.1 is used from lesson two.
- A Developer Edition org and access to any model endpoint. A stub endpoint is provided.
- Course 2.5 is strongly recommended, because every rule about secrets applies here.
Courses that come first
- 2.1 · Apex fundamentals, and the governor limits that shape every design8 hr · Intermediate
- 3.1 · The three places AI can run, and how to choose3 hr · Intermediate
Part of these paths
- AI on SalesforceShareCo Certified AI Practitioner
- The Full StackShareCo Certified Platform Engineer
04Who teaches it
Elliot Saha
Co-founder, Chief Technology Officer
Platform architecture, custom Apex and Lightning Web Components, AI systems, and the Academy platform itself.
05Reviews
No learner reviews yet
This course has not been taken by enough people to publish an honest rating, and we will not print invented quotes on a page that sells verification discipline. Here is what we can evidence instead.
- Assessment
- Lesson checks onlyThis course carries lesson checks. The certificate is issued by the path assessment, not by this course.
- Curriculum version
- 2026.1You enrol into a version. Content changes do not move you mid-course, and your required-lesson count is snapshotted at enrollment.
- Refunds
- 14 daysFull refund within 14 days if you have completed under a quarter of the required lessons. Stated here rather than in a footer.
Start 3.4
Enrol as an individual, or buy seats and assign this course to your team. Progress is reported per lesson, per module and per path.
- 8 hr estimated effort, labs included
- Lifetime access to the version you enrol in
- A ShareCo certificate is not a Salesforce certification