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
Akhil TyagiAkhil Tyagi 

I am getting an error: Syntax error. Missing ')' due to the bold text in the code.

Here is my code:
PassQuery is a string which contains the record ids
<apex:pageBlockTable value="{! retrieveRecords }" var="row">
               
                <apex:column id="checkboxcolumn" >
                    <apex:facet name="header">
                        <apex:inputCheckbox id="headerCheckbox" value="{! checked}" >
                            <apex:actionSupport event="onchange" action="{! headerCheckboxMethod}" reRender="pgblock"/>
                        </apex:inputCheckbox>
                    </apex:facet>
                    <apex:inputCheckbox value="{!If(contains(passQuery, row.Id),true,false)}" id="childCheckBox" >
                        <apex:actionSupport event="onchange" action="{! checkboxStateMethod}" reRender="headerCheckbox">
                            <apex:param name="checkboxId" value="{! row.Id}" assignTo="{! recordId}" />
                        </apex:actionSupport>
                    </apex:inputCheckbox>
                </apex:column>
                
                <apex:column headerValue="Action" title="Action">
                    <apex:outputLink title="Edit Record" value="/{! row.Id}/e?retURL=/apex/DescribeCallAssignment" >Edit</apex:outputLink>|&nbsp;
                    <apex:commandLink title="Delete Record" action="{! deleteRecord}"  reRender="pgblock">Del
                        <apex:param name="recordToBeDeleted"  value="{! row.Id}" assignTo="{! RecordToDelete}" />
                    </apex:commandLink>
                </apex:column>
                <apex:repeat value="{! retrieveColumns}" var="col">
                    <apex:column value="{! row[col]}" />
                </apex:repeat>
            </apex:pageBlockTable>
Best Answer chosen by Akhil Tyagi
Dushyant SonwarDushyant Sonwar
Hi Akhil ,

The issue is that you are using formula expression and apex: input type component uses value binding variables to use its value attributes. You can use wrapper class to show the value in the input checkbox and use that wrapper variable to bind


I have made some changes in your code . Please try using this one.
Visualforce page
<apex:component controller="ComponentController" allowDML="true" id="customcomponent" >
    <apex:attribute name="objectNamecon" description="Value of selcted object" type="String" assignTo="{! objectNameController}" required="true" />
    <apex:attribute name="selectedFieldscon" description="List of selected fields" type="SelectOption[]" assignTo="{! fieldNamesController}" required="true" />
    
    <!-- Tabstyle attribute is used to assign the color scheme to the pageblock.Here Account Object color scheme is used for the pageblock-->
    <apex:pageBlock id="pgblock" title="{!objectNameController} details" >
        <table style="width: 100%">
            <tr>
                <td>
                    <apex:commandButton value="New Record" action="{! newRecord }" />&nbsp;
                    <apex:commandButton value="Delete Selected" action="{! deleteSelectedRecords}" reRender="pgblock" />&nbsp;
                    <apex:commandButton value="Download CSV" action="{! newRecordCSV}" />
                </td>                
            </tr>
        </table>
        <apex:pageBlockSection columns="1" collapsible="false" id="pgBlockSection">
            <apex:pageBlockTable value="{!retrieveRecords }" var="row">
               
                <b><apex:column id="checkboxcolumn" >
                    <apex:facet name="header">
                        <apex:inputCheckbox id="headerCheckbox" value="{! checked}" >
                            <apex:actionSupport event="onchange" action="{! headerCheckboxMethod}" reRender="pgblock"/>
                        </apex:inputCheckbox>
                    </apex:facet>
                    <apex:inputCheckbox value="{!row.isChecked}" id="childCheckBox" >
                        <apex:actionSupport event="onchange" action="{! checkboxStateMethod}" reRender="headerCheckbox, childCheckBox">
                            <apex:param name="checkboxId" value="{! row.Sobj.Id}" assignTo="{! recordId}" />
                        </apex:actionSupport>
                    </apex:inputCheckbox> 
                </apex:column></b>
                
                <apex:column headerValue="Action" title="Action">
                    <apex:outputLink title="Edit Record" value="/{! row.Sobj.Id}/e?retURL=/apex/DescribeCallAssignment" >Edit</apex:outputLink>|&nbsp;
                    <apex:commandLink title="Delete Record" action="{! deleteRecord}"  reRender="pgblock">Del
                        <apex:param name="recordToBeDeleted"  value="{! row.Sobj.Id}" assignTo="{! RecordToDelete}" />
                    </apex:commandLink>
                </apex:column>
                <apex:repeat value="{! retrieveColumns}" var="col">
                    <apex:column value="{! row.Sobj[col]}" />
                </apex:repeat>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        
        <table style="width: 100%">
            <tr>
                <td>               
                    <apex:selectList value="{! recordPerPage }" size="1">
                        <apex:selectOption itemLabel="5" itemValue="5" />
                        <apex:selectOption itemLabel="10" itemValue="10" />
                        <apex:selectOption itemLabel="15" itemValue="15" />
                        <apex:selectOption itemLabel="20" itemValue="20" />
                        <apex:actionSupport event="onchange" reRender="pgblock" />
                    </apex:selectList>
                </td>
                <td align="center">
                    <apex:commandButton value="First" action="{! FirstPage }" disabled="{! HasPreviousPage}" reRender="pgblock" />
                    <apex:commandButton value="Previous" action="{! PreviousPage }" disabled="{! HasPreviousPage}" reRender="pgblock" />
                    <apex:commandButton value="Next" action="{! NextPage }" disabled="{!HasPNextPage}" reRender="pgblock" />
                    <apex:commandButton value="Last" action="{! LastPage }" disabled="{!HasPNextPage}" reRender="pgblock" />
                </td>
                <td align="right">
                    <apex:outputText value="Page {! IF(( offset ==0 ), 1, (numberOfRecords / recordPerPage)) } of {! CEILING(numberOfRecords / recordPerPage) }"></apex:outputText>
                </td>
            </tr>
        </table>        

    </apex:pageBlock>        
</apex:component>

Apex Class
 
public class ComponentController {
    
    //Required Variables-----------------------------------------
    public String objectNameController{ get; set; }
    public List<SelectOption> fieldNamesController{ get; set; }    
    public Integer offset{ get; set; }
    public Integer recordPerPage{ get; set; }
    public Integer numberOfRecords{ get; set; }
    public String characterForSort{ get; set; }
    public Id RecordToDelete{ get; set; }    
    public Id recordId{ get; set; }
    public Boolean checked{ get; set; }
    public Boolean checkChild{ get; set; }
    
    
    //Private Variables-----------------------------------------
    private String query;
    private List<String> columnList;
    private String recordsToPass;
    public Map<Id, Boolean> checkboxState{ get; set; }
    public String passQuery{ get; set; }
    
    //Constructor-----------------------------------------
    public ComponentController(){ 
        offset = 0;
        recordPerPage = 5;
        characterForSort = '';
        numberOfRecords = [SELECT COUNT() FROM Account];
        checkboxState = new Map<Id, Boolean>();
        passQuery = '*';
        checked = false;
        checkChild = false;
    }
    
    //Method for query generation-----------------------------------------
    private String QueryGenerator(){
        
        String str;
        for(Integer i=0; i<fieldNamesController.size(); i++){
            if( i == 0 )
                str = ( 'SELECT ' + fieldNamesController.get(i).getValue() );
            else
                str += ( ', ' + fieldNamesController.get(i).getValue() );
        }
        str += ' FROM ' + objectNameController;
        return str;
    }
    
    //Method for column generation-----------------------------------------
    private List<String> columnListGenerator(){
        List<String> colList = new List<String>();
        for(SelectOption soption : fieldNamescontroller){
            colList.add(soption.getValue());
        }
        return colList;
    }
    
    //Method for getting records to dispay in the table-----------------------------------------
    public List<SobjectWrapper> getretrieveRecords(){
        query = QueryGenerator();
        recordsToPass = query;
        query += (' LIMIT ' + recordPerPage + ' OFFSET ' + offset);
        //return Database.query(query);
        list<SobjectWrapper> lstSobjectWrapper = new list<SobjectWrapper>();
        for(Sobject Obj : Database.query(query)){
            SobjectWrapper wrapperObj = new SobjectWrapper();
            wrapperObj.sobj = Obj;
            wrapperObj.isChecked = (passQuery != null && passQuery.contains(Obj.Id)) ? true : false;
            lstSobjectWrapper.add(wrapperObj);
        }
        return lstSobjectWrapper;
    }
    
    
    //Method for getting columns to display in the table-----------------------------------------
    public List<String> getretrieveColumns() {
        columnList = columnListGenerator();
        return columnList;
    }
    
    //Method on New Record Button-----------------------------------------
    public PageReference newRecord(){
        sObject testRec = Database.query('Select Id from '+ objectNameController +' Limit 1');
        String keyPrefix = String.valueOf(testRec.Id).subString(0, 3);
        PageReference page = new  PageReference('/'+keyPrefix+'/e');
        page.setRedirect(true);
        return page;
    }
    
    //Method on Delete Selected Button
    public void deleteSelectedRecords(){
        List<sObject> recList = new List<sObject>();
        Set<Id> idSet = checkboxState.keySet();
        for(sObject obj : Database.query('SELECT Id FROM '+objectNameController+' WHERE Id in :idSet')){
            recList.add(obj);
        }
        checked = false;
        delete recList;
    }
    
    //Method which directs to CSV download page-----------------------------------------
    public PageReference newRecordCSV(){
        PageReference page;
        if( checkboxState.size() == 0 ){            
            page = new  PageReference('/apex/csvDownloadPage?records='+recordsToPass);
        }
        else{
            passQuery += ('**'+objectNameController+'***');
            for(Integer i=0; i<fieldNamesController.size(); i++){
                if( i == 0 )
                    passQuery += ( fieldNamesController.get(i).getValue() );
                else
                    passQuery += ( ', ' + fieldNamesController.get(i).getValue() );
            }
            passQuery += '****';
            System.debug(passQuery);
            page = new  PageReference('/apex/csvDownloadPage?records='+passQuery);
        }
        
        page.setRedirect(true);
        return page;
    }
    
    //Method on header Checkbox-----------------------------------------
    public void headerCheckboxMethod(){
        List<sObject> objList = Database.query('SELECT Id FROM '+ objectNameController);
        if( checkboxState.size() != objList.size() ){
            checkboxState.clear();
            passQuery = '*';
            for(sObject temp : objList){
                checkboxState.put(temp.iD, true);
                passQuery += (String.valueOf(temp.Id)+',');
            }
        }
        else{
            checkboxState.clear();
            passQuery = '*';
        }
        
        if(!checked){ 
            checked = true;
            checkChild =true;
            System.debug(checked+' ===== '+checkChild);
        }
        else{
            checked = false;
            checkChild = false;
        }
    }
    
    //Method to maintain Checkbox State-----------------------------------------
    public void checkboxStateMethod(){
        List<sObject> objList = Database.query('SELECT Id FROM '+ objectNameController);
        System.debug('Record Id ==== ' + recordId);
        if( checkboxState.containsKey(recordId) ){
            checkboxState.remove(recordId);
            passQuery = passQuery.remove(String.valueOf(recordId)+',');
            System.debug('Map ==== ' + checkboxState);
            System.debug('Query String ==== ' + passQuery);
        }
        else{
            checkboxState.put(recordId, true);
            passQuery += (String.valueOf(recordId)+',');
            System.debug('Map ==== ' + checkboxState);
            System.debug('Query String ==== ' + passQuery);
        }

        if(checkboxState.size() == objList.size()){
            checked = true;
        }
        else{
           checked = false;
        }   
    }
    
    
    //Method on Delete Action-----------------------------------------
    public void deleteRecord(){
        sObject obj = Database.query('SELECT Id FROM '+objectNameController+' WHERE Id = \''+RecordToDelete+'\'');
        try {            
            delete obj;
        } catch (DmlException e) {}
    }
    
    public class SobjectWrapper{
        public boolean isChecked{get;set;}
        public Sobject Sobj{get;set;}
        public SobjectWrapper(){
            isChecked = false;
            
        }
    }    

    
    
    //Pagination methods-----------------------------------------
    public void Firstpage(){ offset = 0; }    
    public void Previouspage(){ offset -= recordPerPage; }
    public void Nextpage(){ offset += recordPerPage; }
    public void Lastpage(){ offset = (((numberOfRecords)/recordPerPage)*recordPerPage); }
    
    //Boolean pagination methods-----------------------------------------
    public Boolean HasPreviousPage{ 
        get{ 
            if(offset == 0 ){
                return true;
            }
            return false;
          }
    
        set;
    }
    
    public Boolean HasPNextPage{ 
        get{ 
            if(offset == (((numberOfRecords)/recordPerPage)*recordPerPage) ){
                return true;
            }
            return false;
          }
        set;
    }  
    
}

This will resolve your issue :)
hope this helps.​​​​​​​

All Answers

Dushyant SonwarDushyant Sonwar
Akhil,

You don't need the If method for this. Try replacing this line 
<apex:inputCheckbox value="{!If(contains(passQuery, row.Id),true,false)}" id="childCheckBox" >
simply by this
<apex:inputCheckbox value="{!contains(passQuery, row.Id)}" id="childCheckBox" >

Hope this helps.
 
Akhil TyagiAkhil Tyagi
Hi Dushyant,

Thank you for the output Dushyant.
I have already made the above-mentioned changes, but the error remains the same.

Hope you can help further.
Dushyant SonwarDushyant Sonwar
HI Akhil ,

Could you post the screenshot of the error message you are getting?

Also post the code of apex class and vf  page that will help to debug the issue.
 
Akhil TyagiAkhil Tyagi
Hi Dushyant,

Sure. Here is my component code:
<apex:component controller="ComponentController" allowDML="true" id="customcomponent" >
    <apex:attribute name="objectNamecon" description="Value of selcted object" type="String" assignTo="{! objectNameController}" required="true" />
    <apex:attribute name="selectedFieldscon" description="List of selected fields" type="SelectOption[]" assignTo="{! fieldNamesController}" required="true" />
    
    <!-- Tabstyle attribute is used to assign the color scheme to the pageblock.Here Account Object color scheme is used for the pageblock-->
    <apex:pageBlock id="pgblock" title="{!objectNameController} details" >
        <table style="width: 100%">
            <tr>
                <td>
                    <apex:commandButton value="New Record" action="{! newRecord }" />&nbsp;
                    <apex:commandButton value="Delete Selected" action="{! deleteSelectedRecords}" reRender="pgblock" />&nbsp;
                    <apex:commandButton value="Download CSV" action="{! newRecordCSV}" />
                </td>                
            </tr>
        </table>
        <apex:pageBlockSection columns="1" collapsible="false" id="pgBlockSection">
            <apex:pageBlockTable value="{! retrieveRecords }" var="row">
               
                <apex:column id="checkboxcolumn" >
                    <apex:facet name="header">
                        <apex:inputCheckbox id="headerCheckbox" value="{! checked}" >
                            <apex:actionSupport event="onchange" action="{! headerCheckboxMethod}" reRender="pgblock"/>
                        </apex:inputCheckbox>
                    </apex:facet>
                    <apex:inputCheckbox value="{!contains(passQuery, row.Id)}" id="childCheckBox" >
                        <apex:actionSupport event="onchange" action="{! checkboxStateMethod}" reRender="headerCheckbox, childCheckBox">
                        	<apex:param name="checkboxId" value="{! row.Id}" assignTo="{! recordId}" />
                        </apex:actionSupport>
                    </apex:inputCheckbox>
                </apex:column>
				
                <apex:column headerValue="Action" title="Action">
                    <apex:outputLink title="Edit Record" value="/{! row.Id}/e?retURL=/apex/DescribeCallAssignment" >Edit</apex:outputLink>|&nbsp;
                    <apex:commandLink title="Delete Record" action="{! deleteRecord}"  reRender="pgblock">Del
                    	<apex:param name="recordToBeDeleted"  value="{! row.Id}" assignTo="{! RecordToDelete}" />
                    </apex:commandLink>
                </apex:column>
                <apex:repeat value="{! retrieveColumns}" var="col">
                    <apex:column value="{! row[col]}" />
                </apex:repeat>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        
        <table style="width: 100%">
            <tr>
                <td>               
                    <apex:selectList value="{! recordPerPage }" size="1">
                        <apex:selectOption itemLabel="5" itemValue="5" />
                        <apex:selectOption itemLabel="10" itemValue="10" />
                        <apex:selectOption itemLabel="15" itemValue="15" />
                        <apex:selectOption itemLabel="20" itemValue="20" />
                        <apex:actionSupport event="onchange" reRender="pgblock" />
                    </apex:selectList>
                </td>
                <td align="center">
                    <apex:commandButton value="First" action="{! FirstPage }" disabled="{! HasPreviousPage}" reRender="pgblock" />
                    <apex:commandButton value="Previous" action="{! PreviousPage }" disabled="{! HasPreviousPage}" reRender="pgblock" />
                    <apex:commandButton value="Next" action="{! NextPage }" disabled="{!HasPNextPage}" reRender="pgblock" />
                    <apex:commandButton value="Last" action="{! LastPage }" disabled="{!HasPNextPage}" reRender="pgblock" />
                </td>
                <td align="right">
                    <apex:outputText value="Page {! IF(( offset ==0 ), 1, (numberOfRecords / recordPerPage)) } of {! CEILING(numberOfRecords / recordPerPage) }"></apex:outputText>
                </td>
            </tr>
        </table>		

    </apex:pageBlock>        
</apex:component>

Here is my controller class:
 
public class ComponentController {
	
    //Required Variables-----------------------------------------
    public String objectNameController{ get; set; }
    public List<SelectOption> fieldNamesController{ get; set; }    
    public Integer offset{ get; set; }
    public Integer recordPerPage{ get; set; }
    public Integer numberOfRecords{ get; set; }
    public String characterForSort{ get; set; }
    public Id RecordToDelete{ get; set; }    
    public Id recordId{ get; set; }
    public Boolean checked{ get; set; }
    public Boolean checkChild{ get; set; }
    
    
    //Private Variables-----------------------------------------
    private String query;
    private List<String> columnList;
    private String recordsToPass;
    public Map<Id, Boolean> checkboxState{ get; set; }
    public String passQuery{ get; set; }
    
    //Constructor-----------------------------------------
    public ComponentController(){ 
    	offset = 0;
        recordPerPage = 5;
        characterForSort = '';
        numberOfRecords = [SELECT COUNT() FROM Account];
        checkboxState = new Map<Id, Boolean>();
        passQuery = '*';
        checked = false;
        checkChild = false;
    }
    
    //Method for query generation-----------------------------------------
    private String QueryGenerator(){
        
        String str;
        for(Integer i=0; i<fieldNamesController.size(); i++){
            if( i == 0 )
                str = ( 'SELECT ' + fieldNamesController.get(i).getValue() );
            else
                str += ( ', ' + fieldNamesController.get(i).getValue() );
        }
        str += ' FROM ' + objectNameController;
        return str;
    }
    
    //Method for column generation-----------------------------------------
    private List<String> columnListGenerator(){
        List<String> colList = new List<String>();
        for(SelectOption soption : fieldNamescontroller){
            colList.add(soption.getValue());
        }
        return colList;
    }
    
    //Method for getting records to dispay in the table-----------------------------------------
    public List<sObject> getretrieveRecords(){
        query = QueryGenerator();
        recordsToPass = query;
        query += (' LIMIT ' + recordPerPage + ' OFFSET ' + offset);
        return Database.query(query);
    }
    
    //Method for getting columns to display in the table-----------------------------------------
    public List<String> getretrieveColumns() {
        columnList = columnListGenerator();
        return columnList;
    }
    
    //Method on New Record Button-----------------------------------------
    public PageReference newRecord(){
        sObject testRec = Database.query('Select Id from '+ objectNameController +' Limit 1');
		String keyPrefix = String.valueOf(testRec.Id).subString(0, 3);
        PageReference page = new  PageReference('/'+keyPrefix+'/e');
        page.setRedirect(true);
        return page;
    }
    
    //Method on Delete Selected Button
    public void deleteSelectedRecords(){
        List<sObject> recList = new List<sObject>();
        Set<Id> idSet = checkboxState.keySet();
        for(sObject obj : Database.query('SELECT Id FROM '+objectNameController+' WHERE Id in :idSet')){
            recList.add(obj);
        }
        checked = false;
		delete recList;
    }
    
    //Method which directs to CSV download page-----------------------------------------
    public PageReference newRecordCSV(){
        PageReference page;
        if( checkboxState.size() == 0 ){            
            page = new  PageReference('/apex/csvDownloadPage?records='+recordsToPass);
        }
        else{
            passQuery += ('**'+objectNameController+'***');
            for(Integer i=0; i<fieldNamesController.size(); i++){
                if( i == 0 )
                    passQuery += ( fieldNamesController.get(i).getValue() );
                else
                    passQuery += ( ', ' + fieldNamesController.get(i).getValue() );
            }
            passQuery += '****';
            System.debug(passQuery);
            page = new  PageReference('/apex/csvDownloadPage?records='+passQuery);
        }
        
        page.setRedirect(true);
        return page;
    }
    
    //Method on header Checkbox-----------------------------------------
    public void headerCheckboxMethod(){
        List<sObject> objList = Database.query('SELECT Id FROM '+ objectNameController);
        if( checkboxState.size() != objList.size() ){
            checkboxState.clear();
            passQuery = '*';
            for(sObject temp : objList){
                checkboxState.put(temp.iD, true);
                passQuery += (String.valueOf(temp.Id)+',');
            }
        }
        else{
            checkboxState.clear();
            passQuery = '*';
        }
        
        if(!checked){ 
            checked = true;
            checkChild =true;
            System.debug(checked+' ===== '+checkChild);
        }
        else{
            checked = false;
        	checkChild = false;
        }
    }
    
    //Method to maintain Checkbox State-----------------------------------------
    public void checkboxStateMethod(){
        List<sObject> objList = Database.query('SELECT Id FROM '+ objectNameController);
        System.debug('Record Id ==== ' + recordId);
        if( checkboxState.containsKey(recordId) ){
            checkboxState.remove(recordId);
            passQuery = passQuery.remove(String.valueOf(recordId)+',');
            System.debug('Map ==== ' + checkboxState);
            System.debug('Query String ==== ' + passQuery);
        }
        else{
            checkboxState.put(recordId, true);
            passQuery += (String.valueOf(recordId)+',');
            System.debug('Map ==== ' + checkboxState);
            System.debug('Query String ==== ' + passQuery);
        }

        if(checkboxState.size() == objList.size()){
            checked = true;
        }
        else{
           checked = false;
        }	
    }
    
    
    //Method on Delete Action-----------------------------------------
    public void deleteRecord(){
        sObject obj = Database.query('SELECT Id FROM '+objectNameController+' WHERE Id = \''+RecordToDelete+'\'');
        try {            
            delete obj;
        } catch (DmlException e) {}
    }
    
    	

    
    
    //Pagination methods-----------------------------------------
    public void Firstpage(){ offset = 0; }    
	public void Previouspage(){ offset -= recordPerPage; }
    public void Nextpage(){ offset += recordPerPage; }
    public void Lastpage(){ offset = (((numberOfRecords)/recordPerPage)*recordPerPage); }
    
    //Boolean pagination methods-----------------------------------------
    public Boolean HasPreviousPage{ 
        get{ 
        	if(offset == 0 ){
            	return true;
        	}
        	return false;
          }
    
        set;
 	}
    
    public Boolean HasPNextPage{ 
        get{ 
        	if(offset == (((numberOfRecords)/recordPerPage)*recordPerPage) ){
            	return true;
        	}
        	return false;
          }
        set;
 	}  
    
}
The part which is giving error is in bold.

Here is the Error:

Error image

Thank you for the input.
 
Dushyant SonwarDushyant Sonwar
Hi Akhil ,

The issue is that you are using formula expression and apex: input type component uses value binding variables to use its value attributes. You can use wrapper class to show the value in the input checkbox and use that wrapper variable to bind


I have made some changes in your code . Please try using this one.
Visualforce page
<apex:component controller="ComponentController" allowDML="true" id="customcomponent" >
    <apex:attribute name="objectNamecon" description="Value of selcted object" type="String" assignTo="{! objectNameController}" required="true" />
    <apex:attribute name="selectedFieldscon" description="List of selected fields" type="SelectOption[]" assignTo="{! fieldNamesController}" required="true" />
    
    <!-- Tabstyle attribute is used to assign the color scheme to the pageblock.Here Account Object color scheme is used for the pageblock-->
    <apex:pageBlock id="pgblock" title="{!objectNameController} details" >
        <table style="width: 100%">
            <tr>
                <td>
                    <apex:commandButton value="New Record" action="{! newRecord }" />&nbsp;
                    <apex:commandButton value="Delete Selected" action="{! deleteSelectedRecords}" reRender="pgblock" />&nbsp;
                    <apex:commandButton value="Download CSV" action="{! newRecordCSV}" />
                </td>                
            </tr>
        </table>
        <apex:pageBlockSection columns="1" collapsible="false" id="pgBlockSection">
            <apex:pageBlockTable value="{!retrieveRecords }" var="row">
               
                <b><apex:column id="checkboxcolumn" >
                    <apex:facet name="header">
                        <apex:inputCheckbox id="headerCheckbox" value="{! checked}" >
                            <apex:actionSupport event="onchange" action="{! headerCheckboxMethod}" reRender="pgblock"/>
                        </apex:inputCheckbox>
                    </apex:facet>
                    <apex:inputCheckbox value="{!row.isChecked}" id="childCheckBox" >
                        <apex:actionSupport event="onchange" action="{! checkboxStateMethod}" reRender="headerCheckbox, childCheckBox">
                            <apex:param name="checkboxId" value="{! row.Sobj.Id}" assignTo="{! recordId}" />
                        </apex:actionSupport>
                    </apex:inputCheckbox> 
                </apex:column></b>
                
                <apex:column headerValue="Action" title="Action">
                    <apex:outputLink title="Edit Record" value="/{! row.Sobj.Id}/e?retURL=/apex/DescribeCallAssignment" >Edit</apex:outputLink>|&nbsp;
                    <apex:commandLink title="Delete Record" action="{! deleteRecord}"  reRender="pgblock">Del
                        <apex:param name="recordToBeDeleted"  value="{! row.Sobj.Id}" assignTo="{! RecordToDelete}" />
                    </apex:commandLink>
                </apex:column>
                <apex:repeat value="{! retrieveColumns}" var="col">
                    <apex:column value="{! row.Sobj[col]}" />
                </apex:repeat>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
        
        <table style="width: 100%">
            <tr>
                <td>               
                    <apex:selectList value="{! recordPerPage }" size="1">
                        <apex:selectOption itemLabel="5" itemValue="5" />
                        <apex:selectOption itemLabel="10" itemValue="10" />
                        <apex:selectOption itemLabel="15" itemValue="15" />
                        <apex:selectOption itemLabel="20" itemValue="20" />
                        <apex:actionSupport event="onchange" reRender="pgblock" />
                    </apex:selectList>
                </td>
                <td align="center">
                    <apex:commandButton value="First" action="{! FirstPage }" disabled="{! HasPreviousPage}" reRender="pgblock" />
                    <apex:commandButton value="Previous" action="{! PreviousPage }" disabled="{! HasPreviousPage}" reRender="pgblock" />
                    <apex:commandButton value="Next" action="{! NextPage }" disabled="{!HasPNextPage}" reRender="pgblock" />
                    <apex:commandButton value="Last" action="{! LastPage }" disabled="{!HasPNextPage}" reRender="pgblock" />
                </td>
                <td align="right">
                    <apex:outputText value="Page {! IF(( offset ==0 ), 1, (numberOfRecords / recordPerPage)) } of {! CEILING(numberOfRecords / recordPerPage) }"></apex:outputText>
                </td>
            </tr>
        </table>        

    </apex:pageBlock>        
</apex:component>

Apex Class
 
public class ComponentController {
    
    //Required Variables-----------------------------------------
    public String objectNameController{ get; set; }
    public List<SelectOption> fieldNamesController{ get; set; }    
    public Integer offset{ get; set; }
    public Integer recordPerPage{ get; set; }
    public Integer numberOfRecords{ get; set; }
    public String characterForSort{ get; set; }
    public Id RecordToDelete{ get; set; }    
    public Id recordId{ get; set; }
    public Boolean checked{ get; set; }
    public Boolean checkChild{ get; set; }
    
    
    //Private Variables-----------------------------------------
    private String query;
    private List<String> columnList;
    private String recordsToPass;
    public Map<Id, Boolean> checkboxState{ get; set; }
    public String passQuery{ get; set; }
    
    //Constructor-----------------------------------------
    public ComponentController(){ 
        offset = 0;
        recordPerPage = 5;
        characterForSort = '';
        numberOfRecords = [SELECT COUNT() FROM Account];
        checkboxState = new Map<Id, Boolean>();
        passQuery = '*';
        checked = false;
        checkChild = false;
    }
    
    //Method for query generation-----------------------------------------
    private String QueryGenerator(){
        
        String str;
        for(Integer i=0; i<fieldNamesController.size(); i++){
            if( i == 0 )
                str = ( 'SELECT ' + fieldNamesController.get(i).getValue() );
            else
                str += ( ', ' + fieldNamesController.get(i).getValue() );
        }
        str += ' FROM ' + objectNameController;
        return str;
    }
    
    //Method for column generation-----------------------------------------
    private List<String> columnListGenerator(){
        List<String> colList = new List<String>();
        for(SelectOption soption : fieldNamescontroller){
            colList.add(soption.getValue());
        }
        return colList;
    }
    
    //Method for getting records to dispay in the table-----------------------------------------
    public List<SobjectWrapper> getretrieveRecords(){
        query = QueryGenerator();
        recordsToPass = query;
        query += (' LIMIT ' + recordPerPage + ' OFFSET ' + offset);
        //return Database.query(query);
        list<SobjectWrapper> lstSobjectWrapper = new list<SobjectWrapper>();
        for(Sobject Obj : Database.query(query)){
            SobjectWrapper wrapperObj = new SobjectWrapper();
            wrapperObj.sobj = Obj;
            wrapperObj.isChecked = (passQuery != null && passQuery.contains(Obj.Id)) ? true : false;
            lstSobjectWrapper.add(wrapperObj);
        }
        return lstSobjectWrapper;
    }
    
    
    //Method for getting columns to display in the table-----------------------------------------
    public List<String> getretrieveColumns() {
        columnList = columnListGenerator();
        return columnList;
    }
    
    //Method on New Record Button-----------------------------------------
    public PageReference newRecord(){
        sObject testRec = Database.query('Select Id from '+ objectNameController +' Limit 1');
        String keyPrefix = String.valueOf(testRec.Id).subString(0, 3);
        PageReference page = new  PageReference('/'+keyPrefix+'/e');
        page.setRedirect(true);
        return page;
    }
    
    //Method on Delete Selected Button
    public void deleteSelectedRecords(){
        List<sObject> recList = new List<sObject>();
        Set<Id> idSet = checkboxState.keySet();
        for(sObject obj : Database.query('SELECT Id FROM '+objectNameController+' WHERE Id in :idSet')){
            recList.add(obj);
        }
        checked = false;
        delete recList;
    }
    
    //Method which directs to CSV download page-----------------------------------------
    public PageReference newRecordCSV(){
        PageReference page;
        if( checkboxState.size() == 0 ){            
            page = new  PageReference('/apex/csvDownloadPage?records='+recordsToPass);
        }
        else{
            passQuery += ('**'+objectNameController+'***');
            for(Integer i=0; i<fieldNamesController.size(); i++){
                if( i == 0 )
                    passQuery += ( fieldNamesController.get(i).getValue() );
                else
                    passQuery += ( ', ' + fieldNamesController.get(i).getValue() );
            }
            passQuery += '****';
            System.debug(passQuery);
            page = new  PageReference('/apex/csvDownloadPage?records='+passQuery);
        }
        
        page.setRedirect(true);
        return page;
    }
    
    //Method on header Checkbox-----------------------------------------
    public void headerCheckboxMethod(){
        List<sObject> objList = Database.query('SELECT Id FROM '+ objectNameController);
        if( checkboxState.size() != objList.size() ){
            checkboxState.clear();
            passQuery = '*';
            for(sObject temp : objList){
                checkboxState.put(temp.iD, true);
                passQuery += (String.valueOf(temp.Id)+',');
            }
        }
        else{
            checkboxState.clear();
            passQuery = '*';
        }
        
        if(!checked){ 
            checked = true;
            checkChild =true;
            System.debug(checked+' ===== '+checkChild);
        }
        else{
            checked = false;
            checkChild = false;
        }
    }
    
    //Method to maintain Checkbox State-----------------------------------------
    public void checkboxStateMethod(){
        List<sObject> objList = Database.query('SELECT Id FROM '+ objectNameController);
        System.debug('Record Id ==== ' + recordId);
        if( checkboxState.containsKey(recordId) ){
            checkboxState.remove(recordId);
            passQuery = passQuery.remove(String.valueOf(recordId)+',');
            System.debug('Map ==== ' + checkboxState);
            System.debug('Query String ==== ' + passQuery);
        }
        else{
            checkboxState.put(recordId, true);
            passQuery += (String.valueOf(recordId)+',');
            System.debug('Map ==== ' + checkboxState);
            System.debug('Query String ==== ' + passQuery);
        }

        if(checkboxState.size() == objList.size()){
            checked = true;
        }
        else{
           checked = false;
        }   
    }
    
    
    //Method on Delete Action-----------------------------------------
    public void deleteRecord(){
        sObject obj = Database.query('SELECT Id FROM '+objectNameController+' WHERE Id = \''+RecordToDelete+'\'');
        try {            
            delete obj;
        } catch (DmlException e) {}
    }
    
    public class SobjectWrapper{
        public boolean isChecked{get;set;}
        public Sobject Sobj{get;set;}
        public SobjectWrapper(){
            isChecked = false;
            
        }
    }    

    
    
    //Pagination methods-----------------------------------------
    public void Firstpage(){ offset = 0; }    
    public void Previouspage(){ offset -= recordPerPage; }
    public void Nextpage(){ offset += recordPerPage; }
    public void Lastpage(){ offset = (((numberOfRecords)/recordPerPage)*recordPerPage); }
    
    //Boolean pagination methods-----------------------------------------
    public Boolean HasPreviousPage{ 
        get{ 
            if(offset == 0 ){
                return true;
            }
            return false;
          }
    
        set;
    }
    
    public Boolean HasPNextPage{ 
        get{ 
            if(offset == (((numberOfRecords)/recordPerPage)*recordPerPage) ){
                return true;
            }
            return false;
          }
        set;
    }  
    
}

This will resolve your issue :)
hope this helps.​​​​​​​
This was selected as the best answer
Akhil TyagiAkhil Tyagi
Hi Dushyant,

Thank you for the help. REally appreciate it.