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:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
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;
And
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?
Edit
I tried disabling the custom Visualforce page, but it still redirected to the Home page, rather than the record page.
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 '17 at 12:19