Contact Us

December 24, 2024

May 13, 2026 1:27 pm

Resolving ConnectApi ConnectApiException in Agentforce Production

Share with

Understanding the Error

The error occurs when the input parameter mapping is incorrect, or the user lacks the necessary permissions to access the Einstein LLM generation API. To resolve this issue, we need to verify the input parameter mapping and ensure the correct permissions are set.

Code Review

The provided Apex class, PromptStringService, is used to send a string to a prompt template using the Einstein LLM generation API. The code is mostly correct, but there is an issue with the input parameter mapping.

PromptStringService.cls

public static String sendStringToPrompt(String textValue) {
    // ...
    Map<String, ConnectApi.WrappedValue> inputParams = 
        new Map<String, ConnectApi.WrappedValue>();
    inputParams.put(INPUT_VARIABLE_NAME, wrappedInput);
    // ...
}

The root cause of the error is the incorrect input parameter mapping. The original code uses ‘Input:’ + INPUT_VARIABLE_NAME as the key for the input parameter map, which is incorrect. The correct key should be the input variable name only.

Fixing the Issue

To fix the issue, we need to correct the input parameter mapping and ensure the correct permissions are set for the user. We can use the following steps:

Checklist

  • Verify the input parameter mapping and correct it if necessary.
  • Check the permissions for the user and ensure they have the necessary permissions to access the Einstein LLM generation API.
  • Use the correct API name for the prompt template.
  • Enable API access for the user.
  • Verify access to the template.

Frequently Asked Questions

What is the correct input parameter mapping?

The correct input parameter mapping is to use the input variable name only as the key for the input parameter map.

How do I verify the API name of the prompt template?

You can verify the API name of the prompt template using SOQL in Workbench or in Developer Console.

What permissions are required to access the Einstein LLM generation API?

The required permissions include Use Einstein Generative AI, Prompt Template access, API Enabled, and access to the template.

How do I enable API access for the user?

You can enable API access for the user by checking the API Enabled box on the user’s profile.

Blogs for the

Business-Savvy!​

Let’s Connect

A 30 min no cost strategy session
with cloud support expert

Let’s Connect

A 30 min no cost strategy session
with cloud support expert