---
schema_version: "1"
id: 79deda2f2b04e052d1bdc8d98fb4ed669591a076b2e3adcf6a4e62d1e4578258
title: setRedirectCode(redirectCode)
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_System_PageReference_setRedirectCode.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_PageReference_setRedirectCode.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: a6f14b4995c888c74a05baa0e4884c684471f25835e7b35263ea7753a041e735
description: Sets the HTTP redirect code to use for the PageReference object when setRedirect(redirect) is set to true.
---
# setRedirectCode(redirectCode)

Sets the HTTP redirect code to use for the PageReference object when [setRedirect(redirect)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_PageReference_setRedirect.htm "Sets the value of the PageReference object's redirect attribute. If set to true, a redirect is performed through a client side redirect.") is set to true.

## Signature

public System.PageReference setRedirectCode(Integer redirectCode)

## Parameters

- **redirectCode**: Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
    
    Valid values:
    
    - 0 — Redirect using the default redirect action for this PageReference. Typically a JavaScript-based redirection or HTTP 302.
        
        ![Note](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/images/icon_note.png)
        
        #### Note
        
        [Site URLRewriter Interface](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/apex_site_urlRewriter.htm "HTML (New Window)") implementations pointing to a PageReference with a redirectCode of 0 are not redirected.
    - 301 — Moved Permanently. Redirect users by sending an HTTP GET request to the target location. Includes instructions to update any references to the requested URL with the target location.
    - 302 — Moved Temporarily. Redirect users by sending an HTTP GET request to the target location. Because the redirection is temporary, it doesn’t include update instructions.
    - 303 — See Other. Redirect users by sending an HTTP GET request to the target location. Not commonly used. Useful when the client sends a POST request and you want the client to call the new web page using a GET request instead of a POST request.
    - 307 — Temporary Redirect. Send the same HTTP request, regardless of the HTTP method, to the target location. Because the redirection is temporary, it doesn’t include update instructions.
    - 308 — Permanent Redirect. Send the same HTTP request, regardless of the HTTP method, to the target location. Includes instructions to update any references to the requested URL with the target location.
    
    If the redirect code contains an invalid integer, an error message is displayed when PageReference is used by Salesforce for redirection.

## Return Value

Type: [System.PageReference](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_system_pagereference.htm "A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.")