Salesforce AI Service Integration
The AI Service feature allows users to interact with external AI services directly from Salesforce Flows or Apex code. It enables both synchronous and asynchronous AI communication, supporting dynamic response schemas for structured responses.
How to use the AI Service functionality?
- Use the ST_AIServiceInvocable action to invoke the AI service from Flow or Apex.
- Set the following fields in the input wrapper:
userMessage
– The main prompt or question for the AI.aiInstructions
– Guidance for how the AI should behave.executeAsync
– Set tofalse
for synchronous,true
for asynchronous calls.
- Optional: Define a schema using either:
responseCustomSchema
for fixed JSON output.recordOrObjectReferenceSchema
andtargetFieldApiNamesSchema
for dynamic object mapping.
- In synchronous mode,
finalResponseMessage
is returned immediately with the AI's response. - In async mode,
id
andthread_id
are returned. Use them with ST_AIGetAsyncResponseInvocable to getfinalResponseMessage
later.

How to fetch asynchronous results?
- Use the ST_AIGetAsyncResponseInvocable class in a Flow or Apex step.
- Pass the
id
andthread_id
received from the initial AI call. - The final AI response will be returned as a String.
- If the result is still processing, the response Status Code will be 204.
