+ Start a Discussion

Saving selected records using custom list controller

Hi all - I am completely new to the custom controllers and cannot figure out how to perform a save on the page if I am using a custom list controller. Basically I needed to create a custom list controller so that I can define the record set that will be returned in the VF Page. Some of the fields on the page are editable and so I want to have a Save button on the page that will save all of the updated records. Here is the code below for my vf page

<apex:page controller="opportunityList2Con"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockTable value="{!opportunities}" var="opp"> <apex:column headerValue="Managers Feel"> <apex:inputField value="{!opp.Manager_Feel__c}"/> </apex:column> <apex:column value="{!opp.StageName}"/> <apex:column value="{!opp.CloseDate}"/> <apex:column > <apex:facet name="header" ><b>Name</b></apex:facet> <apex:outputLink value="/{!opp.id}" > {!opp.name} </apex:outputLink> </apex:column> <apex:column value="{!opp.Owner.Name}"/> <apex:column value="{!opp.Account.Name}"/> <apex:column value="{!opp.Amount}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

and here is the controller. I am not sure how the save should be coded...



public class opportunityList2Con { public PageReference save() { return null; } public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select id, name, account.name, stagename, Manager_Feel__c, closedate, amount, owner.name from Opportunity where ownerid = '00530000000jMqE'])); } return setCon; } set; } public List<Opportunity> getOpportunities() { return (List<Opportunity>) setCon.getRecords(); } }



Hi... In the controller you need to create save method lik "public pagereference save() { /*your code here*/}". In the save method cut the logic in your controller and paste it into the save method. Then it works fine