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
apex_keenapex_keen 

why ApexPages.StandardSetController is needed ?

New to custom controllers ...Why we needApexPages.StandardSetController while writing custom list controllers ? A simple example I was reading was doing something like this : 

public class opportunityList2Con {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[select name,closedate from Opportunity]));
}
return setCon;
}
set;
}
// Initialize setCon and return a list of records
public List<Opportunity> getOpportunities() {
return (List<Opportunity>) setCon.getRecords();
}
}

 

I modified this and inside 'getOpportunities()' function , I directly written that simple query and it was working perfectly fine.

so why need to use  'setcon' property of type ApexPages.Standardsetcontroller and use Database.query locator.. which is making everything look so complex!

Please suggest 

 

Nisse Knudsen.ax1026Nisse Knudsen.ax1026

I couldn't find any proof for that in the documentation right now, but I am pretty sure that you can only use inlineEditing in pageBlockTables when you iterate over a standardSetController (I once used that in a VF page, but it was some while ago!).

Starz26Starz26

No, you can use inline editing in pageblock tables that use a standard controller

 

 

Standard set controller allows for pageination, etc where a standard controller does not. You can also apply filter views etc...

 

Also, just to make sure your question is covered: You do not HAVE to use a standard set controller in your constructor. You could use a standard controller

Nisse Knudsen.ax1026Nisse Knudsen.ax1026

but how would you use inlineEditing for lists in a StandardController ? There is only one record inside, as far as I can see.

 

Starz26Starz26

Nisse Knudsen wrote:

but how would you use inlineEditing for lists in a StandardController ? There is only one record inside, as far as I can see.

 


using an extensions and creating your own lists

Nisse Knudsen.ax1026Nisse Knudsen.ax1026

Starz26 wrote:

Nisse Knudsen wrote:

but how would you use inlineEditing for lists in a StandardController ? There is only one record inside, as far as I can see.

 


using an extensions and creating your own lists




 

Could you maybe provide a short snippet please? I would be definitely interested in your solution, as I didn't like the StandardSetController way, either! 

Thank you!! :)

Starz26Starz26

You can do it using the standard controller single record or lists created in your controller extension:

 

 

from the docs:

 

<apex:page standardController="Contact">
    <apex:form >
        <apex:pageBlock mode="inlineEdit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
                <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
                <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:outputField value="{!contact.lastname}">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                        hideOnEdit="editButton" event="ondblclick" 
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
                <apex:outputField value="{!contact.accountId}"/>
                <apex:outputField value="{!contact.phone}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>