Visualforce pages are not designed to display more than 1000 records in UI. So if you have controller method which returns more than 1000 records and you are displaying the records on UI, then you will receive error "Collection size xxxx exceeds maximum size of 1000" where xxxx is number of records returned by your controller method.
So now if you have to display more than 1000 records on UI, then you can use below options:
For this you have to write the logic in controller and every time you will send request to server in order to render the page.
You can also jquery datatables and pass the JSON data to it to create table for you and you will get pagination, sorting or filtering of records on client side itself which will be very quick.
So we will pass more than 1000 records as a JSON to VF page and by using jQuery, we can build table.
Below is sample apex class and VF page code:
VF page Output (Displaying more than 50000 records)
This will display hyper link to account record. In my example code, I am adding new records to list so id are not present. If you are using query to add records in account list, then you can use above code snippet to show hyperlink.
So now if you have to display more than 1000 records on UI, then you can use below options:
- Use @ReadOnly annotation on method or on page attribute.
As per Salesforce Documetation:
Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. In read-only mode, this limit is relaxed to allow querying up to 1 million rows.
In addition to querying many more rows, the readOnly attribute also increases the maximum number of items in a collection that can be iterated over using components such as <apex:dataTable>, <apex:dataList>, and <apex:repeat>. This limit increased from 1,000 items to 10,000.
- You can restrict the number of records returned by method and provide pagination option using controller method.
For this you have to write the logic in controller and every time you will send request to server in order to render the page.
You can also jquery datatables and pass the JSON data to it to create table for you and you will get pagination, sorting or filtering of records on client side itself which will be very quick.
So we will pass more than 1000 records as a JSON to VF page and by using jQuery, we can build table.
Below is sample apex class and VF page code:
VF page Output (Displaying more than 50000 records)
If you have to dispaly hyperlink on account name, then modify the account name value before adding it to fieldvalues list at line number 19 in apex class as shown below:
sb.name= '<a href=\'/' + sb.id + '\' target=\'_blank\'>' + sb.name+ '</a>';
This will display hyper link to account record. In my example code, I am adding new records to list so id are not present. If you are using query to add records in account list, then you can use above code snippet to show hyperlink.
well and nice tips about uk and their culture. it really good for everything should know before to reach a london. keep update more updates about uk culture. thanks.
ReplyDeleteSAT Training Centre in Chennai
This comment has been removed by the author.
ReplyDeleteWell, and how you get all this data from an object?
ReplyDeleteI see you are creating data in the for loop.
Can you please give some light to this?
Hi Yelmo,
DeleteI have created account in for loop and stored in list.
You can just query account data using SOQL and store it in list and then can use it.
Thanks,
Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards. Custom Patch Maker
ReplyDeleteI love how you broke down complex ideas. It made coding much clearer for me, Thank from BizTrader
ReplyDelete