• subrat.ray1.394549460118714E12
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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