While the World Wide Web has defined a large variety of status codes for HTTP Responses, Salesforce decided to only allow a subset to be used within their applications.
The list is significantly reduced and unfortunately, the well-known ‘418 - I'm a teapot
‘ status code is not attending the party. Same for all Informational (1xx), 203, 205-226, 301-303, 305-308, 402, 406-408, 410-413, 416-429, 451 and 501-511 (see link above for the descriptive naming).
When setting an unsupported status code will cause the response to be overwritten with a ‘500 - Internal Server Error
‘ and an ‘Invalid status code for HTTP response: xxx
‘ message, seen below.
The only solution for this is to select a status code which is part of the Salesforce selection, which can be found in this documentation. For simplicity, I’ve copied the exact list below.
status code | Description |
---|---|
200 | “OK” success code, for GET or HEAD request. |
201 | “Created” success code, for POST request. |
204 | “No Content” success code, for DELETE request. |
300 | The value returned when an external ID exists in more than one record. The response body contains the list of matching records. |
304 | The request content has not changed since a specified date and time. The date and time is provided in a If-Modified-Since header. See Get Object Metadata Changes for an example. |
400 | The request couldn’t be understood, usually because the JSON or XML body contains an error. |
401 | The session ID or OAuth token used has expired or is invalid. The response body contains the message and errorCode. |
403 | The request has been refused. Verify that the logged-in user has appropriate permissions. If the error code is REQUEST_LIMIT_EXCEEDED, you’ve exceeded API request limits in your org. |
404 | The requested resource couldn’t be found. Check the URI for errors, and verify that there are no sharing issues. |
405 | The method specified in the Request-Line isn’t allowed for the resource specified in the URI. |
409 | The request could not be completed due to a conflict with the current state of the resource. Check that the API version is compatible with the resource you are requesting. |
414 | The length of the URI exceeds the 16,384 byte limit. |
415 | The entity in the request is in a format that’s not supported by the specified method. |
431 | The combined length of the URI and headers exceeds the 16,384 byte limit. |
500 | An error has occurred within Lightning Platform, so the request couldn’t be completed. Contact Salesforce Customer Support. |
Did you find any challenges when working with status codes? Feel free to share your experiences!
2 thoughts to “Restricted status codes for HTTP Response in Salesforce”
I have learn several good stuff here. Certainly value bookmarking for revisiting. I wonder how a lot effort you set to make one of these magnificent informative website. Idalia Wilfred Ephraim
Great post. I used to be checking continuously this weblog and I am impressed!
Very helpful info specially the ultimate part 🙂 I deal
with such info a lot. I was looking for this certain information for a very long
time. Thank you and good luck.