You need to sign in to do that
Don't have an account?

Redirect VF to record type selector
I'm attempting to override a standard New button to prevent all but two profiles from creating from that standard button. The problem I'm having is that when I get to the record type selection screen, I click continue and then see the same record type selection screen. After clicking continue again, all is well. I think I'm hitting the standard record type selection page first then I'm being sent to the URL in my extension.
I'm totally a script kitty, but I'm trying so forgive my code if it's bad.
VF page:
I'm totally a script kitty, but I'm trying so forgive my code if it's bad.
VF page:
<apex:page standardController="Work_Orders__c" extensions="newWOextension" action="{!getRedir}" > <apex:pageBlock rendered="{!showError}" > <apex:pageBlockSection ></apex:pageBlockSection> <font color="red" size="4"> <apex:outputText value="Please create new work orders using the button on cases." > </apex:outputText> </font> <apex:form > <apex:commandButton value="Go Back" action="{!Cancel}"/> </apex:form> </apex:pageBlock> </apex:page>Extension:
public without sharing class newWOextension { public boolean showError{ get; set; } public Work_Orders__c record{ get; set; } public newWOextension(ApexPages.StandardController controller) { this.record = (Work_Orders__c)controller.getRecord(); } public PageReference getRedir() { User u = [Select Profile.Name from User where Id = :Userinfo.getUserId()]; showError=true; PageReference newPage; //if the current users profile is not a warranty admin or system admin, show the error message if (u.Profile.Name != 'Warranty Administrator' && u.Profile.Name != 'System Administrator' ) { showError = true; return null; } //otherwise send them to the recordtype selection screen for work orders else { showError=false; return new PageReference('/setup/ui/recordtypeselect.jsp?ent=01I7000000084o3&retURL=%2Fa0V%2Fo&save_new_url=%2Fa0V%2Fe%3FretURL%3D%252Fa0V%252Fo&nooverride=1'); } } private final ApexPages.StandardController controller; }
I did resolve this though with the class below. The user clicks the new button, if they are one role they see an error message, otherwise they are prompted to select their record type, that data is grabbed from the url and they are redirected to the record edit page with the captured parameters added to the end. Credit to Mike Topalovich and his blog here (http://www.topalovich.com/2009/08/force-com-tip-new-button-override-to-assign-visualforce-page-to-specific-record-type-using-native-apex-code/).
My test class:
All Answers
You can always create your own custom URL Parameters. For example, when you create the URL for your button, just write your own parameter like:
Thanks
I did resolve this though with the class below. The user clicks the new button, if they are one role they see an error message, otherwise they are prompted to select their record type, that data is grabbed from the url and they are redirected to the record edit page with the captured parameters added to the end. Credit to Mike Topalovich and his blog here (http://www.topalovich.com/2009/08/force-com-tip-new-button-override-to-assign-visualforce-page-to-specific-record-type-using-native-apex-code/).
My test class: