function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DevSFDevSF 

Redirect to visualforce page new record creation

Hi friends,

My requirement is to redirect my page to a visualforce page when i select a particular record type. and it should autopopulate some fields from its parent object.


Tried using below code and i have overridden the standard new button, but it is redirecting to same visualforce page for all record types, even i have specified the record typeId in my controller.
My requirement is to redirect it to visualforce page for 1 record type && for others it should stick with standard layout.

Below is the code, Please update if anything wrong.

VF PAGE:


<apex:page standardcontroller="Contact" extensions="Redirect"  action="{!getredir}">>
</apex:page>



CONTROLLER:

public class Redirect {

    public Redirect(ApexPages.StandardController controller) {
   //this.c = (Contact)myController.getRecord();

    }
public PageReference getRedir() {

     PageReference newPage;

        if (ApexPages.currentPage().getParameters().get('RecordType') == '012280000015D4W') {
            newPage = Page.Contact_New;
            return newPage.setRedirect(true);
        } else {
            return null;
        }

    }

    private final ApexPages.StandardController controller;
}


Thanks,
Dev.