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
Ben Merton 15Ben Merton 15 

Problem overriding custom tab

I am trying to bypass the standard functionality of a custom tab so that when a user clicks on the tab, it takes them straight to the list view of that item.  I have a controller:
public class PageRef{
public PageReference exit(){
//change the Any_ObjectName__c with your Custom or Standard Object name.
Schema.DescribeSObjectResult anySObjectSchema = Corporate_Statements__c.SObjectType.getDescribe();
String objectIdPrefix = anySObjectSchema.getKeyPrefix();
PageReference pageReference = new PageReference('/'+objectIdPrefix+'/o');
pageReference.setRedirect(true);
return pageReference;
}
}
and a VisualForce page
<apex:page controller="PageRef" action="{!exit}"> </apex:page>
I have overridden the tab with the visualforce page.  However, when you click on the tab now, it seems to go into an endless loop, flicking between two servers c.na22.visual.force.com and na22.visual.force.com.  I have tried loading in another browser (IE) and you can hear the page 'click' opening repeatedly ever few seconds as it evidently tries to open the page.  I have tried creating a VisualForce tab and applying the same functionality, and the same problem occurs

Someone else has checked out the code and said it works okay for them.  This is such a pain!  Any help??

Ben

 
Best Answer chosen by Ben Merton 15
@Karanraj@Karanraj
The problem is with the your url in the code. The actual again take you to the standard tab landing page. Just remove the /o from the url it will take you to the list view section of that particular object.
 
public class PageRef{
public PageReference exit(){
//change the Any_ObjectName__c with your Custom or Standard Object name.
Schema.DescribeSObjectResult anySObjectSchema = Corporate_Statements__c.SObjectType.getDescribe();
String objectIdPrefix = anySObjectSchema.getKeyPrefix();
PageReference pageReference = new PageReference('/'+objectIdPrefix);
pageReference.setRedirect(true);
return pageReference;
}
}