• Rajat Mahajan 14
  • NEWBIE
  • 0 Points
  • Member since 2014

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

This is the code i have : 

PAGE :

<apex:page standardcontroller="Account" extensions="StudentsController" >
  
<script>
alert("Checkvalue");
alert({!acctSSC});
function displayErr(){
      window.alert("Checkvalue:");
}
</script>
   
    <apex:form id="theForm">

        <apex:inlineEditSupport />
   
        <apex:pageBlock Title="All Students List" id="pbAccts">
           
            <apex:pageblockbuttons location="bottom">
                <apex:commandbutton value="Save" action="{!saveAccounts}" onclick="dislayErr()" />
                <apex:commandbutton value="Cancel" action="{!cancel}"/>
            </apex:pageblockbuttons>
           
            <apex:pageBlockTable value="{!accounts}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.website}"/>
                <apex:column value="{!a.phone}"/>
            </apex:pageBlockTable>
              
        <br/>
       
        <apex:outputText value="Please select the number of records to be displayed : "/>
                   
            <apex:selectList size="1" value="{!pageSize}">
                <apex:selectOptions value="{!pageSizes}"/>
                      <apex:actionSupport event="onchange" action="{!updateStandardSetController}" rerender="theForm"/>
            </apex:selectList>
           
            <apex:outputPanel layout="block" styleClass="pSearchShowMore" id="otpNav2">
               
            <!-- <apex:outputText rendered="{!IF(acctSSC.resultSize < 10000,true,false)}"> <b> TOTAL </b> : {!acctSSC.resultSize} &nbsp;&nbsp;&nbsp; </apex:outputText> -->
               
                <apex:commandLink value="Previous Page " action="{!previous}" rendered="{!acctSSC.HasPrevious}" rerender="pbAccts" />  
                <apex:outputPanel style="color: grey;" rendered="{!NOT(acctSSC.HasPrevious)}">Previous Page &nbsp; </apex:outputPanel>        
                <apex:outputPanel style="color:grey;" rendered="{!NOT(acctSSC.HasNext)}">Next Page</apex:outputPanel>        
                <apex:commandLink action="{!next}" value="Next Page" rendered="{!acctSSC.HasNext}" rerender="pbAccts"/>
     
            </apex:outputPanel>
           
        </apex:pageBlock>   
       
    </apex:form>
   
</apex:page>

APEX :

/*
* Description : Controller Class for Students List Page
* Author : Rajat Mahajan
*/

public class StudentsController {

    public StudentsController (ApexPages.StandardController controller){
        pageSize = '5';
        updateStandardSetController();
    }
 
    //Page record size variable 
    public string pageSize {get;set;}
   
    //Standard Set Controller variable for taking all students records (Standard Set controllers methods will be used for working with the collection of records - like pagination)
    public ApexPages.Standardsetcontroller acctSSC {get;set;}
   
    //Constructor will set the default page size of records and also call the method to fetch records   
    public StudentsController (){
       
    }
   
    //Method to fetch records and display only page size records
    public void updateStandardSetController(){
        acctSSC = new ApexPages.Standardsetcontroller(Database.getQuerylocator([SELECT Id, name, website, phone FROM Account]));
        acctSSC.setPageSize(integer.valueOf(pageSize));
    }
   
    //Method to get all records on to the page
    public List<Account> getAccounts(){
        return acctSSC.getRecords();
    }
   
    //Method to set the number of records on the page to be displayed as per user option
    public List<SelectOption> getPageSizes(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('5','5'));
        options.add(new SelectOption('10','10'));
        options.add(new SelectOption('20','20'));
        options.add(new SelectOption('50','50'));
        options.add(new SelectOption('100','100'));
        return options;
    }
   
    //Returns true/false based on records present or not
    public Boolean hasNext{
        get{
            return acctSSC.getHasNext();
        }
        set;
    }

    //Returns true/false based on records present or not
    public Boolean hasPrevious{
        get{
            return acctSSC.getHasPrevious();
        }
        set;
    }

    //Returns previous page of records if present
    public void previous(){
        acctSSC.previous();
    }

    //Returns next page of records if presen
    public void next(){
        acctSSC.next();
    }
   
    public void saveAccounts(){      
       // update acctSSC;      
    }
   
}

---------------------------------
The method saveAccounts :
If i remove the comment : // update acctSSC; (I am basically trying to save the records of StandardSetcontroller

Then i get the following compile time error :
Error Error: StudentsController Compile Error: DML requires SObject or SObject list type: ApexPages.StandardSetController at line 73 column 9

Can you please help me , acctSSC is already of type StandardSetController - I may be doing some mistake.

Please let me know

Regards