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
Vegaln1Vegaln1 

Newbie VF question.

I am trying out some of the  discussions in the  SFDC cookbook and just not making any headway. Page 54 talks about overriding the Account Tab with a VF page based on the user's profile id. This seems easy enough however I would like to do this with a custom object, Contracts__c , that we in place. The steps outlined are;

1. Create  standard account page page

2. Create the custom account page

3. create the controller extension in a APEX class.

4. Add the  profiles via the Security settings for the new pages/

4. Override the Account tab with the page created in step 1.

 

For Step 1, I substituted our custom object instead of 'account':

 

<apex:page standardController="Contracts__c" extensions="overrideCon"

action="{!redirect}">

<apex:detail />

</apex:page>

 

However, when I go to the Contracts__c object to over ride the Contract tab the VF page that I created is not listed. I'm
embarrassed to even be asking this, but what I'm missing that this is not appearing in the drop down menu? Or can't this be done with custom objects in this manner?
 
Thanks.
 
Here's the controller extension right from the book:
 
 
public class overrideCon

{

String recordId;

public overrideCon(ApexPages.StandardController controller)

{

recordId = controller.getId();

}

public PageReference redirect()

{

Profile p = [select name from Profile where Id = :UserInfo.getProfileId()]; if('Symyx Support - Tools'.equals(p.name))

{

PageReference customPage = Page.customContractPage;

customPage.setRedirect(true);

customPage.getParameters().put('Id',recordId);

return customPage;

}

else

{

return null; }

 

}

Message Edited by Vegaln1 on 04-28-2009 08:06 AM
Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Pages that use the standard controller for an object cannot be used as an override for the Tab view of that object.  Using the standard controller implies that you are only dealing with one record (such as in your constructor, where you're pulling the id off of your controller).  Therefore it only makes sense to use this page as an override for a New, Edit, Detail, etc. view -- basically any views that are specific to manipulating or viewing one record.

 

To override the Tab view you will either need a page that uses a Standard List Controller, or no controller, or a custom controller.  I believe all of this is documented in the Visualforce Developer Guide. 

All Answers

jwetzlerjwetzler

Pages that use the standard controller for an object cannot be used as an override for the Tab view of that object.  Using the standard controller implies that you are only dealing with one record (such as in your constructor, where you're pulling the id off of your controller).  Therefore it only makes sense to use this page as an override for a New, Edit, Detail, etc. view -- basically any views that are specific to manipulating or viewing one record.

 

To override the Tab view you will either need a page that uses a Standard List Controller, or no controller, or a custom controller.  I believe all of this is documented in the Visualforce Developer Guide. 

This was selected as the best answer
Vegaln1Vegaln1

Hi Jill.... Thank you for your response. What I find confusing is that the example I was using is pretty much the same as given in the SFDC Cookbook, page 54, in overriding a tab. Is it safe to say that the example in the Cookbook is incorrect?

 

Regards......

 

 

jwetzlerjwetzler
"Pretty much the same" but there's a key difference.  The one in the cookbook is using the Standard List controller, but your example only uses the standard controller.  As mentioned above, pages that use the standard list controller are available as overrides for the Tab view.  So no, the cookbook example is correct.
Vegaln1Vegaln1

Hi Jill... Thanks for getting back to me. The example I'm using is shown under the 'Discussion' section where it states:

 

"To override the Account tab with a custom VF page only for users with ...... ( certain profiles ). "

 

This VF page is supposed to be saved as 'standardAcctPage' and then used in the tab override section of the object.

 

<apex:page standardController="account"

extensions="overrideCon"

action="{!redirect}">

<apex:detail />

</apex:page>

 

Except I used  'Contracts__c' for account: I do see in the first example where it is using a Standard List Controller, but the example here seems to show just the standard Controller??

 

If I add the the  recordSetvar="accounts" to the example I recieve a error on the extenstion line as invalid.

 

jwetzlerjwetzler

Okay I see.  The first example shows a standard list controller.  The second should probably specify overriding a detail page rather than a tab view.  I will log a bug to our doc writers for this, thanks!

 

Once you add the recordSetVar attribute yes, you will need to change or add a constructor that takes in a StandardSetController instead of a StandardController. 

Vegaln1Vegaln1
OK.. thanks.. Are there any examples on how to use StandardSetController. I don't see it in the VF documentation. If I use StandardSetContoller will I be able to redirect and be able to accomplish overriding the tab for only certain profiles?
jwetzlerjwetzler
There is a section for Standard List Controllers in the developer guide.  Should have all you need to know.
jmarie1228jmarie1228

I am not able to create a custom controller for a page, everytime I create the controller attribute and save it to the page I get this error:

Error

Error: Apex class 'CountiesByState' does not exist

 

 
I never see the Create Apex controller button on the page.  I've checked for solutions and am not seeing anyone else with this problem.  Can anyone help?  Is this some setup issue?  I've been our admin/developer for over a year but this is my first attempt at creating a simple VF page.  Thanks in advance
Vegaln1Vegaln1
I'm a  new to this myself but does the CountiesByState APEX class exist? It needs to exist first before the page can be saved I believe.