4

Setup:

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.

Problem:

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 '13 at 20:23
  • I'm hoping to avoid that if possible. – PartOfTheOhana Jun 5 '13 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 – techtrekker Jun 5 '13 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? – Thomas Crouse Jun 5 '13 at 21:06
  • no limiting per se. the record types need to be the ones visible to the user. – PartOfTheOhana Jun 5 '13 at 21:25
1

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;
    }

}
| improve this answer | |
2

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.

| improve this answer | |
0

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;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.