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
Nagesh ENagesh E 

VFP using pageblock table is not saving when i am using some filter

VFP:

<apex:page standardController="Account" extensions="AccountPageblock" recordSetVar="records" id="thePage">
    <apex:form id="theForm">
        <apex:pageBlock id="thePageBlock">
            <apex:pageBlockTable value="{!records}" var="record" id="thePageBlockTable">
                <apex:column >
                    <apex:inputField value="{!record.Name}" id="AccountNameDOM" />
                   <apex:facet name="header">Name</apex:facet>
                </apex:column>
                <apex:column >
                    <apex:inputField value="{!record.Type}" id="AccountTypeDOM" />
                    <apex:facet name="header">Type</apex:facet>
                </apex:column>
                <apex:column >
                    <apex:inputField value="{!record.Industry}"
                        id="AccountIndustryDOM" />  
                        <apex:facet name="header">Industry</apex:facet>
                </apex:column>
                
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Contoller:

public class AccountPageblock {

    public AccountPageblock(ApexPages.StandardSetController controller) {

    }
 
   public List<Account> getrecords() {
return [SELECT Type, Name, Industry FROM Account where Industry =: 'Energy'];
}
public abstract class MyController{
                Apexpages.StandardController controller;
                public MyController(Apexpages.StandardController c){
                controller = c;
                }
                public PageReference save() {
                controller.save();//invoke standard Save method
                return Apexpages.currentPage();//refresh current page
}
}

}

 

Best Answer chosen by Admin (Salesforce Developers) 
sebcossebcos

Hi,

there are some issues with the way you use the controller extension.

One way I have seen your requirement accomplished is here: http://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/ .

This excellent article explains how to use standardsetcontroller.

I have just played around with the code contained in the article and yours to save records:

 

<apex:page controller="AccountPageblock" id="thePage">
    <apex:form id="theForm">
        <apex:pageBlock id="thePageBlock">
            <apex:pageBlockTable value="{!records}" var="record" id="thePageBlockTable">
                <apex:column >
                    <apex:inputField value="{!record.Name}" id="AccountNameDOM" />
                   <apex:facet name="header">Name</apex:facet>
                </apex:column>
                <apex:column >
                    <apex:inputField value="{!record.Type}" id="AccountTypeDOM" />
                    <apex:facet name="header">Type</apex:facet>
                </apex:column>
                <apex:column >
                    <apex:inputField value="{!record.Industry}"
                        id="AccountIndustryDOM" />  
                        <apex:facet name="header">Industry</apex:facet>
                </apex:column>
                
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public class AccountPageblock {

    public PageReference cancel() {
        return con.cancel();
    }


    public ApexPages.StandardSetController con {
        get {
            if(con == null) {
                con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Type, Name, Industry FROM Account where Industry =: 'Energy']));
                // sets the number of records in each page set
                con.setPageSize(5);
            }
            return con;
        }
        set;
    }
 
   public List<Account> getrecords() {
        return con.getRecords();
    }
   
   public PageReference save() {
                return con.save();//invoke standard Save method
                //return null;//refresh current page
}
}