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
Br1Br1 

Reload StandardSetController Records

Hi,

 

I've created a StandardSetController extension and a Visualforce page with a pageblocktable that displays a list of records from a custom object.

 

At the Visualforce page I do some ajax calls to delete a record from this object, then I do a rerender of the pageblocktable to display the list *without* the recently deleted record, but it stills at the list.

 

As I can see, what is happening is that the Set of records are not loaded again when I do the rerender.

How I can reload the set of records? Is possible?

Best Answer chosen by Admin (Salesforce Developers) 
Anand@SAASAnand@SAAS
Are you re-querying the object. If you are using the StandardSetController, I'm assuming you are doing a "Database.queryLocator(<soql to execute>)". Whenever you delete the record, you will need to execute the SOQL again. I don't think changes in the database are automatically reflected in your query locator.

All Answers

Anand@SAASAnand@SAAS
Are you re-querying the object. If you are using the StandardSetController, I'm assuming you are doing a "Database.queryLocator(<soql to execute>)". Whenever you delete the record, you will need to execute the SOQL again. I don't think changes in the database are automatically reflected in your query locator.
This was selected as the best answer
Br1Br1

thx Anand , I figured it out, the StandardSetController must be a property of my Custom Controller

When I do some change I reinitialize the property, (with database.querylocator) and the results are reflected.

 

jdk4702jdk4702

BR1 - can I trouble you for your code?  

 

I'm running into the same issue of trying to re-render a pageBlockTable but can't figure out how to do so.  I'm not sure what you mean by "make StandardSetController a property and re-initialize it".

 

My not working code:

 

 

<apex:page controller="testGetter">
   <apex:pageblock>
        <apex:form>
        <APex:pageblocksection>
                <apex:selectList value="{!inputBox}" size="1" title="Object List"> 
                    <apex:selectOptions value="{!rObjectsInUse}"></apex:selectOptions>
                </apex:selectList>
                <apex:commandButton rerender="preview" value="click me"> 
                      </apex:commandbutton>
        </apex:pageblocksection>
        </apex:form>    
    </apex:pageBlock>
   
    <apex:pageblock>

        <apex:pageBlockSection id="preview">
            <apex:outputtext  value="{!inputbox}"/>
            <br/>
          <apex:pageBlockTable value="{!sRecords}" var="r"> //Doesn't rerender            <apex:column value="{!r.Id}"/>
          </apex:pageBlockTable>
        </apex:pageBlockSection>
  </apex:pageBlock>
    
</apex:page>

 

public with sharing class testGetter {

    public String inputBox { get
    {
        system.debug('input box is: '+inputBox);
        if(inputbox==null){
            inputbox='Account';
        }
        return inputBox;
    }
    
     set; }
     
     public List<SelectOption> getrObjectsInUse(){
        List<SelectOption> options = new List<SelectOption>();
//        AggregateResult[] ars=[SELECT objectName__c name1 FROM Replacer__c WHERE objectName__c!=null AND Active__c=True GROUP BY objectName__c];
        
//        if(ars.size()>0){
//            for (AggregateResult ar:ars){//for 1
//                String objectName=String.valueof(ar.get('name1'));
                options.add(new selectOption('Account','Account'));
                options.add(new selectOption('Contact','Contact'));
                options.add(new selectOption('Lead','Lead'));
//            }//for 1    
//        }//if 1
        return options;
    }
    
    public String recordQuerySQL(){
        String recordQuerySQL = 'SELECT Id FROM '+inputBox;
        system.debug('ObjectName :'+inputBox);
    //make this query logic dynamic based on:
    //1) Object
    //2) Fields in the rules
    //3) Records that meet the "find" criteria        
        return recordQuerySQL;
    }//recordQuerySQL
    
    public ApexPages.StandardSetController setCon{
        get {
            if(setCon==null){
                String query = recordQuerySQL();
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(query));//how do I update this query for the set controller upon button click, which rerenders the PageBlockTable?
            }
            return setCon;
        }//get
        private set;
    }//sRecords
    public List<sObject> getsRecords() {
         return (List<sObject>) setCon.getRecords();
    }   
}

 

 

 

 

jdk4702jdk4702

In case others have my problem, I resolved it by ensuring the setController re-intializes even if not null:

http://community.salesforce.com/t5/Visualforce-Development/How-to-Rerender-StandardSetController-in-PageBlockTable/m-p/193785/highlight/false#M25973