[SalesForce] Override VF page in Service Console

I have a VF page that overrides the standard pages for New/Edit/View actions on the Case object.

However, I wanted to control when a VF page would display, vs when a standard page would display, based on various criteria (profile of user, record type of case, etc).

I accomplished this using a redirect method I wrote into the VF page controller, and using the page parameter nooverride=1, which new prevents the VF page from overriding the standard page. So if I want a user to see the standard page layout, I include that parameter in the returned PageReference object, otherwise I omit it and they see the VF page.

So far so good… then I enabled the Service Console.

The standard SF UI relies heavily on URL parameters for handling navigation between various pages. The service console, not so much… The URL when first opening the console is

https://na29.salesforce.com/console

And that doesn't change when I open and navigate between various tabs/subtabs. If I close the console with a case record open as a tab, then when I return to the console view the URL is

https://na29.salesforce.com/console?tsid=02u34000000jphf

But again, that doesn't change. My VF page's redirect method returns a pagereference with the nooverride=1 parameter, but that's useless to the console because it doesn't pay attention to parameters!

So my question is, how can I control overriding of VF pages through code, in a way that will work both in the standard SF UI and in the service console!

Best Answer

I incorrectly assumed my issue was caused by using the Service Console. Turns out my issue was with how my code redirected to VF or standard layouts.

Here is my full pageRedirect method code, in case anyone runs into a similar issue. Happy to explain details if anyone has questions:

//There are two different VF pages for Cases, one for internal users and one for portal users. 
//This method determines the user and case context (profile and whether new/editing), and redirects to the appropriate page.
//This method is called by CaseRedirect.Page, which is opened by standard Case new/edit/view actions.
public PageReference pageRedirect(){

    string detectedMode;
    map<string, string> pageParameters = ApexPages.currentPage().getParameters();
    string recordTypeID = pageParameters.get('RecordType');
    string returnURL = pageParameters.get('retURL'); 
    string recordTypeName; 

    if(pageParameters.get('Id') == null) detectedMode = 'New';
    else if(pageParameters.get('Id') != null && pageParameters.get('retURL') != null) detectedMode = 'Edit';
    else if(pageParameters.get('Id') != null && pageParameters.get('retURL') == null) detectedMode = 'View';

    if(detectedMode != 'New'){
        Case currentCase = [SELECT ID, RecordTypeID, RecordType.Name FROM Case WHERE ID = :pageParameters.get('Id') LIMIT 1];
        recordTypeID = currentCase.RecordTypeID;
        recordTypeName = currentCase.RecordType.Name;
    }
    else if(recordTypeID != null) recordTypeName = [SELECT Name FROM RecordType WHERE ID = :recordTypeID LIMIT 1].Name;

    //UPDATE (Added 2/11/16)
    //This clause handles a new feature: a custom permission that will grant access to the UCL for individual users, rather than
    //based on profile.
    CustomPermission cperm = [SELECT Id, DeveloperName FROM CustomPermission WHERE DeveloperName = 'Universal_Case_Layout' LIMIT 1];

    //The SetupEntityAccess object is a way to tie custom permissions to the PermissionSet and PermissionSetAssignment object
    List<SetupEntityAccess> setupEntities =
        [SELECT SetupEntityId
           FROM SetupEntityAccess
           WHERE SetupEntityId = :cperm.ID AND
                 ParentId IN (SELECT PermissionSetId
                    FROM PermissionSetAssignment
                    WHERE AssigneeId = :UserInfo.getUserId())];

    boolean hasUCLperm = (setupEntities.size() == 1);

    //If selected Case record type is "Salesforce Issue/Enhancement", don't override with UCL, regardless of user profile.

    if(recordTypeName == 'Salesforce')
    { 

        system.debug('Salesforce record type detected!');
        system.debug('detectedMode: ' + detectedMode);

        if(detectedMode == 'New') return new PageReference('/500/e?ent=Case&nooverride=1&RecordType='+recordTypeID+'&retURL=/500/o');
        else if(detectedMode == 'Edit') return new PageReference('/' + pageParameters.get('Id') + '/e?nooverride=1&RecordType='+recordTypeID+'&retURL=/' + pageParameters.get('Id'));
        else if(detectedMode == 'View') return new PageReference('/' +pageParameters.get('Id') + '?nooverride=1');     
    }

    //If user is a portal/community user
    if(UserInfo.getUserType() == 'PowerCustomerSuccess'){
        User u = [SELECT ID, AccountID, ContactID, ProfileID, IsPortalEnabled, Profile.UserLicenseID FROM User WHERE ID =:UserInfo.getUserID() LIMIT 1];

        //if user is part of our Customer Community, or else has the UCL permission assigned, redirect to VF page
        if(u.ProfileID == CommonUtility.getProfileID('Customer Community Plus User - Custom') || hasUCLperm){
            if(detectedMode == 'New') return new PageReference('/apex/CasePortalUserEdit');
            else if(detectedMode == 'Edit') return new PageReference('/apex/CasePortalUserEdit?id='+pageParameters.get('Id'));
            else if(detectedMode == 'View') return new PageReference('/apex/CasePortalUserView?id='+pageParameters.get('Id'));                
        }
        //else if user is part of our old Client Portal, show standard page
        else{
            if(detectedMode == 'New'){
                recordTypeId = CommonUtility.fetchRecordTypeId('Case', 'Customer_Portal_Assignment_Rule_Case_Record_Type');    
                return new PageReference ('/500/e?nooverride=1&retURL='+returnUrl+'&RecordType='+recordTypeId+'&ent=Case&def_account_id=' + u.AccountID );      
            }
            else if(detectedMode == 'Edit') return new PageReference('/' + pageParameters.get('Id') + '/e?nooverride=1&retURL=/' + pageParameters.get('Id'));
            else if(detectedMode == 'View') return new PageReference('/' +pageParameters.get('Id') + '?nooverride=1');  
        }
    }
    //else if user is an internal employee
    else if(UserInfo.getUserType() == 'Standard'){
        if(UserInfo.getProfileId() == CommonUtility.getProfileID('CS - HEDIS-QI') 
           || UserInfo.getProfileId() == CommonUtility.getProfileID('CS - HEDIS-QI - Josh')
           || UserInfo.getProfileId() == CommonUtility.getProfileID('CS - RTP')
           || UserInfo.getProfileId() == CommonUtility.getProfileID('CS - SOJO')
           || hasUCLperm){
            if(detectedMode == 'New') return new PageReference('/apex/CaseInternalUserEdit');
            else if(detectedMode == 'Edit') return new PageReference('/apex/CaseInternalUserEdit?id='+pageParameters.get('Id'));
            else if(detectedMode == 'View') return new PageReference('/apex/CaseInternalUserView?id='+pageParameters.get('Id')); 
        }

        else{
            if(detectedMode == 'New' && recordTypeID != null) return new PageReference('/500/e?ent=Case&nooverride=1&RecordType='+recordTypeID+'&retURL=/500/o');
            else if(detectedMode == 'New' && recordTypeID == null) return new PageReference('/500/e?ent=Case&nooverride=1&retURL=/500/o');
            else if(detectedMode == 'Edit' && recordTypeID != null) return new PageReference('/' + pageParameters.get('Id') + '/e?nooverride=1&RecordType='+recordTypeID+'&retURL=/' + pageParameters.get('Id'));
            else if(detectedMode =='Edit' && recordTypeID == null) return new PageReference('/' + pageParameters.get('Id') + '/e?nooverride=1&retURL=/' + pageParameters.get('Id'));
            else if(detectedMode == 'View') return new PageReference('/' +pageParameters.get('Id') + '?nooverride=1');       
        }
    }


    return null; 
}