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
monkeykingmonkeyking 

Accessing Data with List Controllers

Hello All,

Can anyone please explain me the below code?

<apex:page standardController="Account" recordSetVar="accounts" extensions="MyControllerExtension">
<apex:pageBlock >
<apex:pageBlockTable value="{!accounts}" var="acc">
<apex:column value="{!acc.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

public with sharing class MyControllerExtension {
private ApexPages.StandardSetController setController;
public MyControllerExtension(ApexPages.StandardSetController setController)
{
this.setController = setController;
Account [] records = [SELECT Id, Name FROM Account LIMIT 10]; setController.setSelected(records); } }

In the previous example, i have used only the VF page for displaying list of accounts. Now in this example i am using a controller to select the records.

So now what will be my expected output for this? Because when i run the above code, there is no difference between the previous and the one with controller.
Please let me know.

Thanks.

Regards,
Rajkumar CV
Khan AnasKhan Anas (Salesforce Developers) 
Hi Rajkumar,

Greetings to you!

You can display the list of records using Standard List Controller or Custom  Controller. You will get the same output. 

Standard controllers can provide all of the functionality and data that you need for your Visualforce page. These are provided by the platform so you can produce Visualforce pages without writing apex code. You'd use these when you have a singe object to manipulate.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std.htm

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_about.htm

The custom controller can override existing functionality, make new actions available to the page, customize the navigation, use HTTP callouts or web services, have greater control of how information is accessed on the page.

A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-level security of the current user.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas