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.
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
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.
000392650

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.