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 to false for synchronous, true for asynchronous calls.
  • Optional: Define a schema using either:
    • responseCustomSchema for fixed JSON output.
    • recordOrObjectReferenceSchema and targetFieldApiNamesSchema for dynamic object mapping.
  • In synchronous mode, finalResponseMessage is returned immediately with the AI's response.
  • In async mode, id and thread_id are returned. Use them with ST_AIGetAsyncResponseInvocable to get finalResponseMessage later.
Example of using the AI Assistant in Flow Builder.

How to fetch asynchronous results?

  • Use the ST_AIGetAsyncResponseInvocable class in a Flow or Apex step.
  • Pass the id and thread_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.
Fetching final result from asynchronous AI call.