1

My use case is that I have overridden the 'View' button with a Visualforce page which immediately redirects to either a Visualforce page or the standard detail page based on the RecordType. I would like to extend this functionality to the 'New' button so that after the record type is selected, I navigate appropriately.

However, I have been unable to find a method that generates the page for a new record. Using edit() on the standardController throws an error. Any advice?

1 Answer 1

2

Have you tried returning a PageReference to /003/e? That's the page that you get to create a new contact.

Try this:

Visualforce:

<apex:page controller="NewContactController">
    <apex:form>
        <apex:commandButton action="{!NewContact}" value="New Contact"/>
    </apex:form>
</apex:page>

Controller:

public with sharing class NewContactController {
    public pageReference NewContact()
    {
        return new PageReference ('/003/e?RecordType=<your record type ID>');
    }
}

This will take you to the contact creation page whenever you click the 'New Contact' button.

If what you want is to specify a specific record type it might be doable via the queryString... would have to investigate a bit more.

2
  • That seems to have the same effect as pressing the button, causing a redirect loop. Additionally, we do need to specify a record type. Mar 4, 2016 at 20:04
  • 1
    In order to specify a record type, all you need to do is add the following to the query string: ?RecordType=<your record type ID>
    – mkorman
    Mar 7, 2016 at 17:24

You must log in to answer this question.

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