Loading

Troubleshooting Named Credentials HTTP Callout Error: System.UnexpectedException in Salesforce Apex

Veröffentlichungsdatum: May 18, 2026
Beschreibung

Users may encounter errors with HTTP callouts in Salesforce Apex when Named Credentials are involved. The error message typically appears as:
System.UnexpectedException: Script-thrown exception
This error can occur during HTTP callout execution in Apex when there is a configuration issue with the Named Credential used as the callout endpoint.

Lösung

Troubleshooting Steps for Named Credentials HTTP Callout Error

There can be multiple reasons for this error. Before raising a case with Salesforce Support, verify the following steps to diagnose and resolve the issue.

Step 1: Verify Named Credential API Name

Confirm that the callout name used in your Apex method matches the Named Credential's API name in Setup.
To check: navigate to Setup > Named Credentials and compare the API Name with the string used in your Apex callout (for example, callout:MyNamedCredential). If there is a mismatch, update the Apex code or the Named Credential to use the same API name.
Reference: Named Credentials as Callout Endpoints

 Step 2: Check URL Reserved Characters

Verify if the callout URL path contains reserved characters that require URL encoding. URL reserved characters such as spaces, slashes, and special symbols must be percent-encoded. For example, a backslash \ should be encoded as %5c.

Reference:  URL reserved characters 

Step 3: Check Remote Endpoint URL Path Filtering

Verify whether the remote endpoint has stricter URL path filtering enabled. For example, some endpoints replace \ with %5c. This behavior is controlled at the endpoint level and not within Salesforce.

Nummer des Knowledge-Artikels

000392650

 
Laden
Salesforce Help | Article