0

I have a visualforce page with two controllers that contains a selectList with all the Schema objects in my org. The selectlist when selected and pressed the "saved to DB" button saves the option into the DB but does not reload the table. The table only refreshes the new values when the page is reloaded.

The variable "List<sObject__c> sObjectToShow{get;set;}" from the extended controller is updated with the values but does not render in the table. Visualforce page: `

<apex:pageBlock title="sObject List" mode="edit">

    <table width="100%" border="0">
        <tr>
            <td width="200" valign="top">
                <apex:form >
                    <apex:pageBlock title="Schema" mode="edit" id="schemaList">
                        <apex:pageBlockButtons location="top" >
                            <apex:commandButton value="Save to DB" action="{!saveObjectSelectedToDB}" reRender="table" />
                            <apex:commandButton value="Load All" action="{!saveObjectSelectedToDB}"  />
                        </apex:pageBlockButtons>

                        <apex:selectList value="{!ItemsSelected}" size="15" multiselect="true" id="selectItemsList">
                            <apex:selectOptions value="{!ObjectList}"/>
                        </apex:selectList>
                    </apex:pageBlock>
                </apex:form>
            </td>
            <td valign="top"> <!-- **************************************************************-->

                <apex:outputPanel id="tableOutputPanel">
                    <apex:form >

                        <apex:pageBlock title="sObject DB Pagination " id="objectResults">
                            <apex:pageMessages />
                            <apex:pageBlockButtons location="top" >

                                <apex:commandButton value="Delete Selected" action="{!processSelected}" rerender="table"/>
                                <apex:commandButton value="First" action="{!beginning}" disabled="{!DisablePrevious}"/>
                                <apex:commandButton value="Previous" action="{!previous}" disabled="{!DisablePrevious}"/>
                                <apex:commandButton value="Next" action="{!next}" disabled="{!DisableNext}"/>
                                <apex:commandButton value="Last" action="{!last}" disabled="{!DisableNext}"/>
                                <apex:commandButton value="Reset DB" action="{!saveObjectSelectedToDB}"  />

                            </apex:pageBlockButtons>

                                <apex:pageBlockTable value="{!sObjectToShow}" var="objectsToShow" id="table">
                                    <apex:column >
                                        <!-- This is our selected Boolean property in our wrapper class -->
                                        <apex:inputCheckbox value="{!objectsToShow.Selected_Delete_From_Shema_DB__c}"/>
                                    </apex:column>
                                    <apex:column headerValue="Object">
                                        <apex:outputField value="{!objectsToShow.API_Name__c}"/>
                                    </apex:column>
                                </apex:pageBlockTable>

                        </apex:pageBlock>

                    </apex:form>
                </apex:outputPanel>
            </td>
        </tr>
    </table>
  </apex:pageBlock>

`
First controller:

public class SCHAPP_ControllerDisplayObjectDetail {

    // set of sObject Names
    public Set<String> objectSet = new Set<String>();
    // list of Objects to be displayed in the select list
    public List<SelectOption> displayObjListSchema = new List<SelectOption>();
    // list of fields to display
    public List<Schema.SObjectField> listOfFields {get; set;}
    // list of items selected in the select list
    public List<String> ItemsSelected  {get; set;}
    // map of the fields from the objects selected
    public Map<String,SObjectField> objectFields {get; set;}
    // map of the objects in the schema
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    // map of object of the inner class before converting to custom object
    public Map <String, objectClass> mapObjectClass = new Map<String, objectClass>();


    //constructor
    public SCHAPP_ControllerDisplayObjectDetail(){

    }

    //get Object list from the Schema.getGlobalDescribe called from page
    public List<SelectOption> getObjectList(){
        //System.debug('inside the getOjbectlist');

        for(Schema.SObjectType objTyp : schemaMap.Values()){
            //adding the object name to the set, so that we do not add duplicates to the list.
            if(!objectSet.contains(objTyp.getDescribe().getName())){
                objectSet.add(objTyp.getDescribe().getName());
                //create new inner class sObject object
                objectClass newObject = new objectClass(objTyp.getDescribe().getLabel(),objTyp.getDescribe().getName(),objTyp.getDescribe().getKeyPrefix(),objTyp.getDescribe().isCustom() );
                // place object inside a map to search later on
                mapObjectClass.put(objTyp.getDescribe().getName(), newObject);
                // list of sObjects form the Schema.getGlobalDescribe used to display in the select list
                displayObjListSchema.add(new SelectOption(objTyp.getDescribe().getName(), objTyp.getDescribe().getLabel()));

            }
        }// end for

        // sort the Schema list
        displayObjListSchema.sort();

        //System.debug('return displayObjectListSchema');
        return displayObjListSchema;
    }



}// end class

`
Second extended controller where the Visualforce page gets the displaying informaiton for the table.

public class SCHAPP_Pagination {

    //List to store all the sObject in DB
    public List<sObject__c> allSObjects {get; set;}
    //List to show the limited sObjects on the page
    public List<sObject__c> sObjectToShow{get;set;}
    //We create a new list of sObjects that we be populated only with sObjects if they are selected
    public List<sObject__c> selectedSObjects {get;set;}


    public SCHAPP_Pagination(SCHAPP_ControllerDisplayObjectDetail controller) {
        sObjectToShow = new List<sObject__c>();
        allSObjects = new list<sObject__c>();
        System.debug('contructor of SCHAPP_ControllerDisplayObjectDetail');

        allSObjects = [SELECT API_Name__c, Selected_Delete_From_Shema_DB__c FROM sObject__c];
        totalSize = allSObjects.size();
        //for pagination
        if((counter+limitSize) <= totalSize){
            for(Integer i=0;i<limitSize;i++){
                sObjectToShow.add(allSObjects.get(i));
            }
        }else{
            for(Integer i=0;i<totalSize;i++){
                sObjectToShow.add(allSObjects.get(i));
            }
        }
    }// end constructor 

}// end class
2
  • Please note you can select a code block and hit the {} editor button (or CTRL+K) to auto-indent. – Adrian Larson Feb 1 '18 at 0:35
  • Put only the related code specific to the issue. That way your code will be readable and members can understand and could guide you – Santanu Boral Feb 1 '18 at 3:57
0

Got the solution, I wasn´t repopulating the pagination List.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.