What I'm trying do is, when the user clicks on the Custom Button I want that to redirect to a Standard page in edit mode

Here is what I have done so far: In the standard page layout:

Label `Clone Testing`
Created `Custom Button or Link Edit`
Content Source: `URL`


Placed the above custom button created on the standard page layout.

So when clicked on the above custom button I see the blank screen and the URL is still pointing to the EmployeeClonePage?id=xxxx

What I expect/want is that to refresh the page to display the new id

EmployeeClonePage Page:

<apex:page controller="EmployeeCloneController" action="{!CloneMe}">  


public void CloneME() 
   //insert got the newId

private pageReference redirectMe(Id newId) {
   return new PageReference('/'+newId+'/e?retURL=/'+newId);

What I'm doing wrong here?

  • 1
    I actually want to point out that you want to go to /apex/EmployeeClonePage?id={!Employee__c.Id}, not to /EmployeeClonePage?id={!Employee__c.Id} Mar 23, 2017 at 18:56

2 Answers 2


Your visualforce page is calling CloneME() (via the action attribute), which returns precisely nothing (not even null, which is probably why your current controller code isn't causing an infinite loop of page reloading).

To redirect to another page, you'll need to change your method signature to return a pageReference.

return redirectMe(someId); should then accomplish what you are looking to do.

  • Derek: one question though how would you open a blank new page and copied the data from old record?
    – Nick
    Mar 23, 2017 at 19:15
  • @NickKahn That's really something that should be another question (which, ideally, you would make an attempt to research on your own before asking). What you're asking for is record cloning. I hope you can take that and run with it.
    – Derek F
    Mar 23, 2017 at 19:53

Best way to navigate to Edit screen with the use of StandardController.

public PageReference CloneME() 
   //insert got the newId
   return (new ApexPages.StandardController (new Employee__c(Id=newId))).edit();

To return to detail page:

return (new ApexPages.StandardController (new Employee__c(Id=newId))).view();

You must log in to answer this question.

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