Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am stuck in a situation, hope so I could get some help here.

I'm having a condition where I want to redirect a page to one URL. It is related to service cloud console.

In controller I defined a merge variable :

public string finalURL {get; set;}

VF page :

<apex:commandButton action="{!save}" value="Save" onComplete="refreshTab({!isError});"/>

and I am using this memebr variable in Javascript.

Javascript code :

<script type="text/javascript">

           function refreshTab(isError) {
               if (!isError) {
           function refreshTabById(tabId) {
               if(sforce && sforce.console && sforce.console.isInConsole()) {
                   sforce.console.refreshPrimaryTabById(, true);
               } else {
                   var urlString = {!finalURL}; //''
                   window.location = urlString;


But, the issue is, when code is coming to the else condition, the page is not redirecting to the new URL defined. Any idea?

share|improve this question

Your custom button code is throwing a JavaScript exception.

This is because {!finalURL} will dump an unescaped URL out into the middle of your source code - you will want to put quotes '' around him like so, and escape for good measure also:

var urlString = '{!JSENCODE(finalURL)}'; //
window.location.href = urlString;

(Regal has a good point too: window.location will still work, but it's better practise to use href)

share|improve this answer

You should use: window.location.href instead of window.location.

  • window.location is an object you shouldn't assign a string to object.
  • window.location.href is a property that tells you the current URL location of the browser.
 window.location.href = ''; //Will redirect you to Google immediately.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.