Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Creating a Dispatcher
<apex:page standardController="Opportunity"
public class OpportunityNewDispatcherController{
private final ApexPages.StandardController controller;
public OpportunityNewDispatcherController(ApexPages.StandardController stdController) {
this.controller = stdController;
public PageReference redirect() {
PageReference pr;
String rtId = ApexPages.currentPage().getParameters().get('RecordType');
if (rtId == null) {
// If a record type wasn't passed in, we need to determine the user's default
List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Opportunity.RecordTypeInfos;
//check each one
for (Schema.RecordTypeInfo rti : infos) {
if (rti.isDefaultRecordTypeMapping()) {
rtId = rti.getRecordTypeId();
RecordType recordType = [select DeveloperName from RecordType where Id = :rtId];
if (recordType.DeveloperName == 'Special_RT') {
// send the user to a VF page
pr = Page.SomeVFPage;
} else {
Schema.DescribeSObjectResult r = Opportunity.SObjectType.getDescribe();
pr = new PageReference('/' + r.getKeyPrefix() + '/e');
// add the nooverride parameter to keep us out of an endless loop
pr.getParameters().put('nooverride', '1');
// For some reason the save_new parameter is sent which tries to autosave the page
return pr.setRedirect(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.