Loading

Salesforce Apex — PageReference setRedirect() Returns HTTP Status Code 200 Instead of a 3XX Redirect

Data pubblicazione: May 28, 2026
Descrizione

When a Visualforce page is redirected using the Apex setRedirect() method on a PageReference object, the HTTP response code returned is 200 (OK) rather than a 3XX redirect status code (such as 301 Moved Permanently or 302 Found). Developers who check the HTTP status code to confirm that a redirect has occurred may be confused by this behavior.

Risoluzione

Why setRedirect() Returns 200

This behavior is expected and is by design. The setRedirect() method in Salesforce Apex performs a server-side forward, not a server-side redirect. The distinction is important:

  • A server-side redirect sends a 3XX HTTP response to the browser, which then makes a new request to the target URL. The browser's address bar changes to the new URL.
  • A server-side forward processes the request on the server and returns the result of the target page directly to the client, all within the same HTTP request. Because the server handles the forwarding internally, the HTTP response code returned to the client is 200 (OK) — the browser receives the content of the forwarded page without ever issuing a new HTTP request.

When setRedirect(true) is called in an Apex controller, Salesforce performs this server-side forward. The forwarded request is handled by the target page on the same server, and the result is returned to the client as a 200 response.
Example scenario: If you call setRedirect(true) in an Apex controller and inspect the browser's Network tab using Chrome DevTools, you will see a 200 response for the page navigation — not a 301 or 302. This is correct behavior.

Numero articolo Knowledge

000383215

 
Caricamento
Salesforce Help | Article