Syntax

Redirect(url, movedPermanently)
2 arguments

Parameters

Name Type Required Description
url string Yes The address to send the browser to.
movedPermanently boolean Yes true issues an HTTP 301 Moved Permanently redirect; false issues an HTTP 302 Found (“Moved Temporarily”) redirect. Use false unless you are certain the move is permanent — browsers cache 301 responses aggressively and may skip re-checking the original URL.

Description

Redirect(url, movedPermanently) sends the visitor’s browser to another URL. Runtime testing proves the bare name is injected by Platform.Load("core", ...) and performs the redirect — but only in the same scope the load ran in. Inside nested helper-function bodies (or eval()), the bare name is undefined. Its sibling Platform.Response.Redirect() works in any scope and requires no Platform.Load.

Examples

Bare-name form (same scope as Platform.Load)

Platform.Load("core", "1.1.5");
Redirect("https://www.example.com", false);

Scope-independent form — Platform.Response.Redirect

Platform.Response.Redirect("https://www.example.com", false);

Known bug — redirect inside try/catch

This caveat applies to Platform.Response.Redirect() as well: if a try block contains a redirect, the redirect triggers the catch block. In the example below the intended redirect to salesforce.com is overridden by the catch redirect to example.com:

try {
    Platform.Response.Redirect("https://salesforce.com", false);
} catch (ex) {
    Platform.Response.Redirect("https://example.com", false);
}

Keep redirects out of try blocks, or guard the catch so it does not perform its own redirect.

See Also