My custom object has different record types and an overwritten edit page.
I want to implement a 'Save & New'- Button on this VF page which redirects my users to the record type selection page.
How can I implement this in my controller extension of the VF page?

I tried to implement the solution from DavinC. First it worked fine, but since Summer '14 it redirects me to the Record Type Selector and if I choose a Record Type and press Continue nothing happens.

VF page button:

<apex:commandButton value="Save & New" action="{!doSaveAndNew}"/>

Controller Extension method:

public PageReference doSaveAndNew() {
        PageReference result = null;        

        try {  
            upsert myObject;
            String myObjectEntityId = CustomSettings__c.getAll().values().get(0).txt_myObjectEntityId__c;
            result = new PageReference('/setup/ui/recordtypeselect.jsp?ent=' + myObjectEntityId + '+&retURL=myObjectEditPage&save_new_??url=' + myObjectEntityId + '/e');        
        catch(Exception ignore) {}

        return result;

Take a look at the URL for the recordtype selection page for the object in question. For Opportunity for example, it's:


006/e being the standard Opportunity edit page.

It should be a similar approach for all objects.

  • 1
    Ok, I created al PageReference with the complete link I posted above and it works. Looks freaky but it works. Thanks for your advice.
    – David Renz
    Jun 30 '14 at 13:00
  • The only problem is that if I upload the package and install it on another org it won't work, because of the hardcoded IDs.
    – David Renz
    Jun 30 '14 at 13:11
  • 1
    There won't be any hardcoded IDs. 006/e is a static URL for the Opp. edit page - there will be an equivalent URL for your object. RetURL will be generated in your VF page controller, with the URL of your VF page or some other record perhaps. Jun 30 '14 at 13:13
  • 1
    Here is how you can dynamically pull the object ID, this should avoid any issues with a hardcoded ID problem in a client org: salesforce.stackexchange.com/questions/31788/… Jun 30 '14 at 13:32
  • Unfortunately this don't work since the Summer '14 release.
    – David Renz
    Jul 22 '14 at 10:19

Your action method for Save and New should create a page reference to the record type selection page which you can find out by creating a new record. This will be the standard record type selection page. Also your retUrl should be set to the custom visualforce page so that the user is taken to the VF page once he selects the record type.

  • I think the page I reference in the retURL is the URL where the user is redirected if he clicks Cancel. I have to set the save_new_url to the custom visualforce page to redirect the user if he selects a record type.
    – David Renz
    Jul 24 '14 at 8:51

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.