0

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`

/EmployeeClonePage?id={!Employee__c.Id}

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}">  
</apex:page>

EmployeeCloneController:

public void CloneME() 
{
   //SOQL....
   //insert got the newId
   redirectMe(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} – Sebastian Kessel Mar 23 '17 at 18:56
0

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 Kahn Mar 23 '17 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 '17 at 19:53
1

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

public PageReference CloneME() 
{
   //SOQL....
   //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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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