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
SynclairSynclair 

Redirecting to custom object list view after clicking save in Visualforce

Hi,  
I have a visualforce page for a custom object. It uses standard controller and an extension.  I want to take users to the object listview after saving the record or cancelling.  Here is my Visualforce and Apex coce.  After I click save nothing happens.   Thanks for your help!

Visualforce:
<apex:page standardController="Self_Matrix__c" extensions="e1">
  <apex:form >
    <apex:pageBlock title="">
    
          <apex:pageblockButtons >
              <apex:commandbutton action="{!save}" value="Save"/>
          </apex:pageblockButtons>
              <apex:pageblockButtons >
              <apex:commandbutton action="{!cancel}" value="cancel"/>
          </apex:pageblockButtons>
                
          <apex:pageblockSection >
              <apex:inputfield value="{!Self_Matrix__c.name}"/>
              <apex:inputfield value="{!Self_Matrix__c.Date__c}"/>
              <apex:inputfield value="{!Self_Matrix__c.student_ID__c}"/>
              <apex:inputfield value="{!Self_Matrix__c.Type__c}"/>        
          </apex:pageblockSection>
          <apex:pageBlockSection title="Housing" columns="1">
             <apex:pageblockTable value="{!Self_Matrix__c}" var="act" >
              <apex:column headerValue="1" headerClass="headingCenter" > 
                 <apex:outputLabel > Subject.</apex:outputLabel>
              </apex:column>
              <apex:column headerValue="3" headerClass="headingCenter">
                 <apex:outputLabel > Interest.</apex:outputLabel>
              </apex:column>
              <apex:column headerValue="Student Goal" headerClass="headingCenter"> 
                 <apex:outputLabel value=""> </apex:outputLabel>
                 <apex:inputCheckbox value="{!act.Student_Goal__c}" style="float:center"/>
              </apex:column>
         </apex:pageblockTable>
       
       </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>
 
Apex:
public class e1 {
    public e1(ApexPages.StandardController controller) {}
public static PageReference listView(Schema.sObjectType destinationSObject) {
   Schema.DescribeSObjectResult destination = Self_Matrix__c.SObjectType.getDescribe();
   PageReference pageRef = new PageReference('/' + destination.getKeyPrefix() + 'a/o' );
   pageRef.setRedirect(true);
   return listView(Self_Matrix__c.sObjectType);
    }
}
Akshay SAkshay S
I hope below article will help you :
http://codewithajay.blogspot.com/2016/03/redirecting-to-selected-list-view.html