I have a VF page that is called from a button. It acts like a router and has params attached to it. I need to send the user to either of the following based on logic

  1. the record selector for task and then the standard page for task (done.)
  2. the record selector for task and then a VF task page.


No idea how to accomplish #2

  • Can't you just display your own RecordType picker? @zachelrath's answer salesforce.stackexchange.com/a/12179 is pretty badass starting point...
    – eyescream
    Jun 5, 2013 at 20:23
  • I'm hoping to avoid that if possible. Jun 5, 2013 at 20:29
  • 1
    I'd imagine you should be able to use the standard recordtype.jsp page that comes up as standard, just grab the URL and return as the PageReference Jun 5, 2013 at 20:38
  • Do you need to limit the available record types in the picklist depending upon some other factor, or are all the record types that are available to the user able to be selected? And do you absolutely need a custom page for some record types instead of having multiple page layouts? Jun 5, 2013 at 21:06
  • no limiting per se. the record types need to be the ones visible to the user. Jun 5, 2013 at 21:25

3 Answers 3


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:

string customParameter = 'My Record Type';
pageReference pgRef = new pageReference ('/apex/myVFPage?customParam='+customParameter);

Then in your VF page's initilization, grab the parameter and use it however you wish:

public class Cntrlr_myVFPage{
    private Task myTask;

    public Cntrlr_myVFPage(){
        string recordTypeName=ApexPages.currentPage().getParameters().get('customParam');
        myTask = new Task();
        myTask.RecordTypeId =[Select Id,SobjectType,Name From RecordType Name =:recordTypeName and SobjectType ='Task'  limit 1].Id;


You could point the button to the URL: /setup/ui/recordtypeselect.jsp?ent=Task&retURL=REDIRECT_URL_ON_CANCEL&save_new_url=REDIRECT_URL_WHEN_USER_ON_CONTINUE

The "REDIRECT_URL_ON_CANCEL" & "REDIRECT_URL_WHEN_USER_ON_CONTINUE" parameters will need to be URL encoded (you can do this with http://meyerweb.com/eric/tools/dencoder/), and the "REDIRECT_URL_WHEN_USER_ON_CONTINUE" will be URL of a custom Visualforce page. This page will have "RecordType=RECORD_TYPE_ID" appended to the URL, which you can access via ApexPages.currentPage().getParameters().get('RecordType') in the page controller.

On page load you could then redirect to the standard Task edit view if you wish, just make sure you pass the RecordType URL parameter to the new PageReference.

Feel free to leave a message if you require further assistance.


Here is some code which demonstrates @techtrekker's suggestion.

This code checks to see if the current user has a contactid on their User account and routes to the native recordtype.jsp page according to some defined logic.

public PageReference pageRoute(){

    User currentUser = [SELECT Id
                                , ContactId
                        FROM User 
                        WHERE Id = :UserInfo.getUserId()];

    // the page reference to be returned
    PageReference returnPR; 

    // First, check to see whether this person has a contactid
    system.debug('currentUser.ContactId:  ' + currentUser.ContactId);

    if ( currentUser.ContactId != null ) {          
        // User has a contactId on their User account, sending them to some 
        // defined page which isn't the recordtype selection screen

        returnPR = new PageReference('/001/e');             
    } else {
        // no contactid, send them to the recordtype selection screen
        // with the parameters used by that page contained in the URL

        // set the page for the 'cancel' action on the recordtype screen
        PageReference returnPage = new PageReference('/003/o');

        //set the page for the 'continue' action on the recordtype screen
        PageReference save_new_page = new PageReference('/001/e');
        save_new_page.getParameters().put('nooverride', '1');
        save_new_page.getParameters().put('retURL', '/003/o');  

        // build the reference to the recordtype selection screen
        returnPR = new PageReference('/setup/ui/recordtypeselect.jsp');

        // set the entity type for the recordtype screen
        returnPR.getParameters().put('ent', 'Account');

        // add the two page URLs to the recordtype screen URL
        returnPR.getParameters().put('save_new_url', save_new_page.getURL());
        returnPR.getParameters().put('retURL', returnPage.getURL());  

    return returnPR;

You must log in to answer this question.

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