Last active
August 29, 2015 14:01
-
-
Save dhoechst/85a37afef1f2428a3f56 to your computer and use it in GitHub Desktop.
Creating a Dispatcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Opportunity" | |
extensions="OpportunityNewDispatcherController" | |
action="{!redirect}"> | |
</apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
pr.getParameters().putAll(ApexPages.currentPage().getParameters()); | |
// 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 | |
pr.getParameters().remove('save_new'); | |
return pr.setRedirect(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment