Use Salesforce Einstein / Agentforce APIs to invoke a prompt template and retrieve a model-generated response from Apex

domain: developer.salesforce.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

In-depth guide

Salesforce Bulk API 2.0 limits — the full failure-mode walkthrough related to developer.salesforce.com, checked against official docs, with linked verified routes.

Steps

  1. Create a Prompt Template in the Prompt Builder Setup UI, specifying input fields and grounding context
  2. In Apex invoke the template using the ConnectApi.LlmOpenAiActions.executePromptTemplate method or the equivalent REST endpoint under /services/data/vXX.0/einstein/
  3. Pass a map of merge field values to populate the template inputs at runtime
  4. Parse the response object to extract the generated text from the generations array
  5. Handle rate-limit and token-limit errors; implement retry with exponential backoff as these are external AI service calls
  6. Log input/output pairs for audit purposes given data residency and compliance requirements common in enterprise CRM contexts

Known gotchas

Related routes

Invoke a Salesforce Prompt Template via the Connect REST API (Prompt Builder)
developer.salesforce.com · 6 steps · unrated
Invoke an Einstein Prediction Builder model score from Apex using the ConnectApi.EinsteinAI methods to enrich a lead record at save time
salesforce.com · 5 steps · unrated
Generate text and chat completions using the Salesforce Einstein Models API (einstein/platform)
developer.salesforce.com · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans