+ Start a Discussion
mariappangomathirajmariappangomathiraj 

Enquire about Standard set controller

I have used Standard set controller to query the accounts object.... Accounts object have more than 4000 records..... i am passing the list to page the standard set controller pass only 2000 records....if any possible to pass all 4000 records to my visual force page....????????

AdrianCCAdrianCC

Hello,

 

Use next() and previous() to advance through the records and retrieve them using getRecords(). See documentation here: http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm

 

Thanks,

Adrian 

mariappangomathirajmariappangomathiraj

Thanks Adrian....But I am using Next Function in my controller the Page taken next 2000 records in my account....Not all records...So how to get all records in my page??? Can u help me for this solution....

 

In My page I am showing 2000 records per page...So how to show all records in my page..In My Page shows last 2000 records..So how to get all records to show in page?

Here My class is...

 

public class AccountsController{

public ApexPages.StandardSetController Accounts {get; set;}
public List<Account> AccountList{get; set;}

public AccountsController() {

AccountList = new List<Account>();

Accounts = new ApexPages.StandardSetController(Database.getQueryLocator([ SELECT Id,Name
FROM Account
]));

Accounts.setPageSize(2000);
Accounts.next();
AccountList = (List<Account>)Accounts.getRecords();
}


AdrianCCAdrianCC

Wow... how many records do you have?!

 

I mean, even 2000 records are a bit too much to show in one page... it's not too easy for a user to read that. Why don't you do some pagination? Show x records on the page and have a next and a previous buttons that will show the next x records and the previous x records. 

 

LE: you can try to create a List<List<Account>> from your Accounts, where each interior list has 2000 elements. Use getHasNext() and next() to create it.

Maybe this will fool the page limit...

 

Adrian 

mariappangomathirajmariappangomathiraj

Thanks Adrian...................I have nearly 5000 records..... In my page I shows all records in same page..... I don't want any pagination in my page................ But In standard set controller gets only 2000 records from all 5000 records....... Because I set Pagesize is 2000..... So Database.getQueryLocator takes only 2000 records..... So any possible to get other remaining records or any possible to get all records in Database.getQueryLocator in Standard set Controller?????????

AdrianCCAdrianCC

Sorry for the late response.

 

From what I understand the QueryLocator should return ALL of your records. You can only access them in batches of 2000. That's what I've understood from the documentation: http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm

 

So your code should look like this:

 

...
Accounts = new ApexPages.StandardSetController(Database.getQueryLocator([ SELECT Id,Name FROM Account])); // this retrieves ALL 5000 records

List<List<Account>> acclst = new List<List<Account>>();

while (Accounts.getHasNext()) {
    Accounts.next();
    acclst.add((List<Account>) Accounts.getRecords());
}
//acclst should have 3 elements -> 3 lists

Pls test this and tell me if it works.

 

Thank you,

Adrian 

 

mariappangomathirajmariappangomathiraj

Thanks Adrian......

I including your coding and test my code....but it's not working... i didn't know about "How to pass three list to acclst???can u help for this solution........