function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rtscottrtscott 

Override Custom Object Tab with Visualforce Page Help

Hello,

I have done a fair amount of research on this topic, but I am still unclear on how to accomplish the following two things:

1. We are using Salesforce's Customer Portal product. We have built two custom objects and are displaying tabs for these custom objects in our Customer Portal. We have also built controller extensions for these custom objects to extend the functionality of the standard controllers. We want to display Visualforce pages when a user clicks on the tabs for these objects in the Customer Portal. In order to override the tabs for these objects with a Visualforce page, we cannot specify a standardContoller using the same object name in the Visualforce page. If we do, the VF page is not given as an option when you try to override the tab. If the VF page does not have a standardController specified, we can use it to override the tab, but we cannot link our controller extension to the page.

For example, I have a custom object called "Contact Us". I want to override the tab for this object with the following Visualforce page:

Code:
<apex:page standardController="Contact_Us__c" extensions="ContactUsExtensions">
  <h1>Custom Contact Us Page</h1>
</apex:page>

I am not given the option to override the "Contact Us" custom object tab with this page. It will only allow me to override it with a page that does not have a standardController specified. Why is that?

2. In addition to above, we need to show the standard "Contact Us" homepage when a user clicks on the "Contact Us" tab in the regular Salesforce interface, and we need to show a custom Visualforce page when a user clicks on the "Contact Us" tab in the Customer Portal. To do this, we created a new controller, ContactOverride - here is the code:

Code:
public class ContactOverride {
    public ContactOverride() {

    }


   String recordId;

public ContactOverride(ApexPages.StandardController
       controller) {recordId = controller.getId();}

public PageReference redirect() {
  Profile p = [select name from Profile where id =
               :UserInfo.getProfileId()];
  if ('Customer Portal User'.equals(p.name)
      || 'Customer Portal Test'.equals(p.name))
      {
       PageReference customPage =
Page.PortalContactUs;
       customPage.setRedirect(true);
       customPage.getParameters().put('id', recordId);
       return customPage;
      } else {
         return null; //otherwise stay on the same page
      }
   }
}

This code was lifted directly from the Force.com Cookbook (pages 53-56) and modified slightly to fit our needs. Basically, the controller sends users in the profiles "Customer Portal User" or "Customer Portal Test" to a custom Visualforce page (PortalContactUs) when they click on the "Contact Us" tab. If the user is not in either of those profiles, they stay on the same page.

Then, we created a new Visualforce page called ContactRedirect that looks like this:

Code:
<apex:page controller="ContactOverride" action="{!redirect}">
   <apex:detail />
</apex:page>

and override the tab on the "Contact Us" custom object with this page.

Again, we took this code from the Force.com Cookbook (pages 53-56) and modified it slightly. (The instructions in the Cookbook tell us to set a standardController and use the override controller we built as an extension. However, we cannot override the tab with a standardController set as explained in issue 1.)

This seems to work, but we would prefer that users who are not in the "Customer Portal User" or "Customer Portal Test" profiles see the standard "Contact Us" homepage under the "Contact Us" tab, and not the "ContactRedirect" VF page. Is there a way to change the controller (ContactOverride) to do this?

What are the best solutions to these issues?

Thanks for any help that you can offer,

-- Robert
 

 

BenLBenL

Hopefully you already found the answer but in case not...

 

In order to use a VF page to override an object home tab it must have one of 3 things;

 

1. use something other than the standard controller

2. use no controller at all

3. references the standard list controller for that object i.e. if you are trying to override the lead home page <apex:page standardController = "Lead" recordSetVar="leads">

dev33dev33

Can you use a visualforce tab instead of overriding the custom object's tab with a visualforce page?

RickNTARickNTA

Robert, I wonder if you ever solved your 1st problem?  We have a very similar situation, also using the customer portal (which I don't think is a factor in our problem).  As far as I can tell it's impossible to override a custom object tab with a functional page (i.e., one with a controller), which seems ridiculous, but I can't find anything that explains it or works.  The developer doc completely overlooks the issue, so it's essentially wrong.  Great fun.  But I guess if we were using a real development platform we'd have to find something else to do on Sat. morning...

subrat.ray1.394549460118714E12subrat.ray1.394549460118714E12
Try with this one

<apex:page standardController="Contact_Us__c" recordSetVar="Contact_Us__c" extensions="ContactUsExtensions">
  <h1>Custom Contact Us Page</h1>
</apex:page>
Rajesh..Rajesh..
@subrat.ray1.394549460118714E12 thanks its works for me...