I've got a custom Visualforce Page that overrides the standard record view on an object called Opportunity__c.

I've got a Custom Button on Account with the following code:

var result = sforce.apex.execute("AccountAction","convertToOpportunity",{a:"{!Account.Id}"});
parent.location.href = '/'+result[0].Id+'/e';

What this does is that when a User is on an Account record, it invokes the following code below:

WebService static Opportunity__c convertToOpportunity(Id a) {
  Account account = [SELECT Id, Name FROM Account WHERE Id = :a];

  Opportunity__c opp = new Opportunity__c(
    Name = account.Name,
    OwnerId = UserInfo.getUserId(),
    Account__c = account.Id
    // Other stuff...

  INSERT opp;

  return opp;

This code create an Opportunity__c record, as expected, and redirects the user to the Standard edit page.

The problem I've got is what happens when the User clicks Save. Rather than redirect to the record, it redirects to the home page.

I feel like the problem is in the following line:

parent.location.href = '/'+result[0].Id+'/e';

I've tried the following:

parent.location.href = '/'+result[0].Id+'/e?retUrl='+result[0].Id;


parent.location.href = '/'+result[0].Id+'/e?saveUrl='+result[0].Id;

Whilst these successfully go into the Url, they seem to make no difference to where the page actually redirects to.

How can I get the page to redirect to the record page, once the user has finished editing it?


I tried disabling the custom Visualforce page, but it still redirected to the Home page, rather than the record page.

  • Hi Dan. Did you check that your variable result[0].Id contains the right value? Jan 16, 2017 at 12:16
  • @MartinLezer It does. All the convertToOpportunity() function does is creates a brand new record, the intention is to then redirect the User to the Edit Page of that new record. That all works fine, it's just when the User clicks "Save" on the standard Edit Page does it redirect to the Home Page, rather than the Record Page.
    – Dan Jones
    Jan 16, 2017 at 12:19
  • It seems that you can use the window.location.replace(url) method to simulate an http redirect. I think you should try that. Jan 16, 2017 at 12:52
  • @MartinLezer I've got it and posted an answer below, it was just a case-sensitivity problem... Do'h!
    – Dan Jones
    Jan 16, 2017 at 13:00

1 Answer 1


I've got it.

I was reading this article and although I was right to be using:

parent.location.href = '/'+result[0].Id+'/e?saveUrl='+result[0].Id;

The problem was just a case of, case-sensitivity.

parent.location.href = '/'+result[0].Id+'/e?saveURL='+result[0].Id;

Note the capitalised saveURL.

Once I made that little change, it worked as expected.

According to that article, Salesforce behaves by prioritising in the following:

  1. Is there a saveURL URL parameter set? If so, redirect to that.
  2. Is there a retURL URL parameter set? If so, redirect to that.
  3. Redirect to /home/home.jsp

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .