A callout works in the sandbox and throws in production. How do you approach it?
Testing How you read an error that names its own fix — whether you take the hint and stop there.
An Apex class posts to a partner endpoint. It has been running in the full
sandbox for two weeks. The first production run throws
System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings.
The message names the setting, so I would check Remote Site Settings in production first and compare it to the sandbox. But I would also look at where the URL comes from, because if it is typed into the Apex class then the sandbox and production are only working by coincidence, and the fix is a Named Credential rather than another entry in a setup list.
Sandbox drift is the whole story here. Two weeks of sandbox runs proved
the code, not the configuration, and the two orgs were never the same
shape. So I add the remote site to unblock the release, then treat the
literal URL as the actual defect: move it behind a Named Credential so the
endpoint and its credentials travel as metadata, the Apex says
callout:Partner_API/orders, and Remote Site Settings stops being part of
the story at all. That also kills the class of bug where a sandbox refresh
silently repoints an integration at live partner data.
- Is the endpoint the same URL in both orgs, or does the sandbox point at a test host?
- Is the URL coming from a Named Credential, a custom setting, or a string literal in the class?
Add the endpoint to Remote Site Settings in production and close the ticket.
That clears the error in about a minute and leaves the URL wherever it already was. The next environment fails identically, and if the URL is a literal in Apex then changing hosts is a code deployment. The exception is telling you the endpoint is not managed anywhere.
They'll ask next Does a Named Credential still need a Remote Site Setting?
No. The Named Credential is itself the authorisation for that host, which is one of the better reasons to use one.
They'll ask next How would you have caught this before production?
A deployment check that fails when an Apex callout contains a literal
https://. It is a crude rule and it catches this every time.