The Ultimate Guide to HTTP Status Codes for Salesforce Callouts

When connecting Salesforce with other systems, it’s important to understand HTTP status codes. These codes tell you if your callouts worked or failed and help you fix issues quickly. Here’s a list of the most common ones you’ll see in Salesforce integrations.

HTTP Status Codes Table

Below is a table summarizing the most common HTTP status codes and their meanings:

Status CodeCategoryDescription
200 OKSuccessThe request was successful, and data was returned as expected.
201 CreatedSuccessA new resource was successfully created.
204 No ContentSuccessThe request succeeded, but there’s no data to return.
301 Moved PermanentlyRedirectionThe resource has been moved to a new URL.
302 FoundRedirectionThe resource is temporarily at a different URL.
400 Bad RequestClient ErrorThe request is invalid due to syntax or data issues.
401 UnauthorizedClient ErrorAuthentication failed; credentials are missing or invalid.
403 ForbiddenClient ErrorYou don’t have permission to access the resource.
404 Not FoundClient ErrorThe resource doesn’t exist or the URL is incorrect.
408 Request TimeoutClient ErrorThe server took too long to respond.
429 Too Many RequestsClient ErrorAPI rate limit exceeded; wait and retry later.
500 Internal Server ErrorServer ErrorThe server encountered an unexpected error.
502 Bad GatewayServer ErrorThe server received an invalid response from another server.
503 Service UnavailableServer ErrorThe server is down or overloaded; try again later.
504 Gateway TimeoutServer ErrorThe server didn’t get a response in time from an upstream server.

2xx: Success Codes

These codes mean the request worked as expected.

  • 200 OK: The request was successful, and you got the data you needed. For example, a successful GET or POST call will return this.
  • 201 Created: The request was successful, and a new record was created. This is common when using POST to add data to an external system.
  • 204 No Content: The request was successful, but there’s no data to return. For example, this happens when you delete a record.

3xx: Redirection Codes

These codes mean the resource has moved to another location.

  • 301 Moved Permanently: The resource has been moved to a new URL. Update your endpoint in Salesforce.
  • 302 Found: The resource is temporarily at a different location. This is rare but may happen with some APIs.

4xx: Client Error Codes

These codes mean something is wrong with the request.

  • 400 Bad Request: The request has a problem, like invalid JSON or wrong parameters. Check and fix the data you’re sending.
  • 401 Unauthorized: Your authentication failed. Make sure your API keys, tokens, or OAuth setup are correct.
  • 403 Forbidden: You’re not allowed to access the resource. Double-check your permissions for the API.
  • 404 Not Found: The resource doesn’t exist. Ensure the URL and any identifiers are correct.
  • 408 Request Timeout: The server took too long to respond. This can happen if the network is slow. Try again or optimize the call.
  • 429 Too Many Requests: You’ve hit the API’s rate limit. Wait and retry after some time or handle requests in smaller batches.

5xx: Server Error Codes

These codes mean something went wrong on the server side.

  • 500 Internal Server Error: The server had an unexpected issue. Log this and contact the API’s support if it keeps happening.
  • 502 Bad Gateway: The server got an invalid response from another server. Retry the request after a short delay.
  • 503 Service Unavailable: The server is overloaded or down for maintenance. Retry with delays.
  • 504 Gateway Timeout: The server didn’t get a response in time. Like 503, retrying the request can help.

Best Practices for Handling HTTP Status Codes in Salesforce

  1. Log Responses: Always log the status codes and error messages for debugging.
  2. Retry Logic: Retry temporary issues like 503 and 504 with short delays.
  3. Handle Errors Gracefully: Show clear error messages to users and avoid crashing your app.
  4. Respect Rate Limits: Monitor API usage to avoid 429 Too Many Requests errors. Use backoff logic for retries.

Conclusion

Knowing HTTP status codes helps you troubleshoot and improve your Salesforce integrations. Use these codes to understand what’s happening with your callouts and make your applications more reliable. By following these tips, you’ll build stronger and more efficient connections with external systems.

Leave a Comment