Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I need to override the standard 'New' button with a VF page.

Based on the record type selection, I am able to redirect to different pages.

now my challenge is to decide the VF page redirection based on PageLayout assignment(both record type and profiles) not based on RecordType alone.

I'm not sure if this is possible in Salesforce. Can anyone pls let me know the solution/work around?

share|improve this question
    
Here's a link to a feature request which would make this immensely easier: Assign Visualforce Pages like Page Layouts --- vote it up and spread the word! –  zachelrath Dec 26 '12 at 12:43
add comment

2 Answers

I think there are three general approaches you can take here:

  1. (Preferred) Use the $Profile global variable, in conjunction with detecting the Record Type either from URL Parameters or from the object' RecordType.Name field, in a giant case statement. For instance, the following page could be used to override the Account object's New action, assuming that there are Account record types and that you are not skipping the Record Type selection screen in your override:

    <apex:page standardController="Account" action="/apex/{!CASE($Profile.Name,
        'System Administrator',
            CASE($CurrentPage.Parameters.Record_Type,
               'Industrial Account','NewIndustrialAccount_SystemAdmin',
               'Education Account','NewEducationAccount_SystemAdmin',
              'Healthcare Account','NewHealthcareAccount_SystemAdmin','DefaultNewAccount_SystemAdmin'
            ),
        'Sales Manager',
            CASE($CurrentPage.Parameters.Record_Type,
               'Industrial Account','NewIndustrialAccount_SalesManager',
               'Education Account','NewEducationAccount_SalesManager',
               'Healthcare Account','NewHealthcareAccount_SalesManager','DefaultNewAccount_SalesManager'
            ),    
        CASE($CurrentPage.Parameters.Record_Type,
           'Industrial Account','NewIndustrialAccount_Default',
           'Education Account','NewEducationAccount_Default',
           'Healthcare Account','NewHealthcareAccount_Default','DefaultNewAccount_SystemAdmin'
        )    
     )}"/>
    
  2. (Complicated and probably not worth it) Use the Web Services API's describeLayout call from within JavaScript in a "dispatcher" page to retrieve an object's actual Page Layout Assignments and then use these to redirect to appropriate Visualforce Pages.

  3. Use a 3rd party tool like Skuid to manage the creation of custom interfaces to override standard actions --- Skuid's Page Assignments feature is specifically designed to assist in providing this sort of dispatch functionality for custom Visualforce interfaces.
share|improve this answer
    
Thanks for your reply.. –  Priyanka Dec 27 '12 at 5:06
    
Did my answer help in solving your problem? If so please vote up so that others will benefit. –  zachelrath Dec 27 '12 at 15:22
add comment

You can deal with this redirect inside the controller, if you use an init method in your page:

<apex:page controller="TheController" action="{!Init}" ... 

Simply check the RT provided and then redirect the user if it doesn't match the one you're interested in:

public PageReference Init()
{
    // Grab the ID (or IDs in a list of the RT we don't want to redirect:
    Id objRTId = [select Id from RecordType where SObjectType = 'TheObj__c' and DeveloperName = 'TheRT' limit 1][0].Id;
    String chosenRT = ApexPages.CurrentPage().GetParameters().Get('RecordType');

    // If no match, then redirect to the standard page by using 'nooverride=1'
    if(chosenRT != objRTID)
    {
        // redirect to the standard new screen
        String url = '/' + TheObj__c.SObjectType.GetDescribe().GetKeyPrefix() + '/e?RecordType=' + chosenRT + '&nooverride=1';

        return new ApexPages.PageReference(url).SetRedirect(true);
    }

    return null;
}

Note that instead of using override=0 or sfdc.override=0 as you might expect from looking at the URL of the Visualforce page, the parameter to use is nooverride which must be set to 1.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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