3

It's very easy open the detail page of a new record created in a custom controller of a visual force page.

Example code:

public PageReference save() {
…….
        PageReference acctPage = new PageReference('/' + Influencer.id);
        acctPage.setRedirect(true);
        return acctPage;
    }

But i would like to be able to open the page of the new record in edit mode.

Please, can you help me?

Thanks in advantage for any advice.

2 Answers 2

6

All you have to do is attend '/e' (edit). Adding the retURL parameter will take an url to which the page should navigate on save and cancel actions. If you don't add this the page will default to going to the homepage.

PageReference acctPage = new PageReference('/'+ID+'/e?retURL=%2Fa'+ID);

will do what you want. Not sure if there are more dynamic ways to get that.

1
  • 6
    You can also do this: public PageReference save() { return new ApexPages.StandardController(Influencer).edit(); } This has the advantage of using the standard utility that forms the correct link for you; if salesforce.com changes their behavior later, this code will still get the correct url.
    – sfdcfox
    Aug 17, 2013 at 12:51
0

Hi Samuel return new ApexPages.StandardController(Influencer).edit(); this one works but after landing in edit mode cancel and save options are not working. But this one is the solution to edit the record from apex.

1
  • Welcome to SFSE! Please take the tour and read How to Answer. Do note that this site isn't built for back-and-forth discussion. Also, be aware that you're replying to a question that's nearly 11 years old (and it seems you're trying to reply to sfdcfox, not Samuel). URL-hacking like this doesn't work so well in the current UI (lightning experience) If you have a different question, you should create your own question. You can link back to this question to help provide some context.
    – Derek F
    Feb 16 at 3:51

You must log in to answer this question.

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