Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2023 16:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save arun12209/8c1c79f76d70091915b445f1c6eb7b89 to your computer and use it in GitHub Desktop.
public with sharing class LazyLoadingController {
public static Map<String, Object> getContactRecords(Integer pageSize, Integer page) {
Integer offset = Math.max(0, (page - 1) * pageSize);
List<Contact> contacts = [SELECT Id, Name, Email, Phone FROM Contact ORDER BY Name ASC LIMIT :pageSize OFFSET :offset];
Integer totalRecords = [SELECT COUNT() FROM Contact];
Map<String, Object> result = new Map<String, Object>();
result.put('contacts', contacts);
result.put('totalRecords', totalRecords);
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment