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.

HTTPResponse-418Teapot-ServerError
Screenshot showing CRIS (build on Salesforce) to respond with ‘418 – I’m a teapot’ HTTP Status code, but the listening party to get an 500 – Internal Server Error, stating the status code is invalid.

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 codeDescription
200“OK” success code, for GET or HEAD request.
201“Created” success code, for POST request.
204“No Content” success code, for DELETE request.
300The value returned when an external ID exists in more than one record. The response body contains the list of matching records.
304The 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.
400The request couldn’t be understood, usually because the JSON or XML body contains an error.
401The session ID or OAuth token used has expired or is invalid. The response body contains the message and errorCode.
403The 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.
404The requested resource couldn’t be found. Check the URI for errors, and verify that there are no sharing issues.
405The method specified in the Request-Line isn’t allowed for the resource specified in the URI.
409The 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.
414The length of the URI exceeds the 16,384 byte limit.
415The entity in the request is in a format that’s not supported by the specified method.
431The combined length of the URI and headers exceeds the 16,384 byte limit.
500An 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!

How useful was this post?

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

2 thoughts to “Restricted status codes for HTTP Response in Salesforce

  • Idalia

    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

    Reply
  • best CBD oil

    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.

    Reply

Leave a comment

Your email address will not be published. Required fields are marked *