Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created July 9, 2023 16:13
Show Gist options
  • Save arun12209/8c1c79f76d70091915b445f1c6eb7b89 to your computer and use it in GitHub Desktop.
Save arun12209/8c1c79f76d70091915b445f1c6eb7b89 to your computer and use it in GitHub Desktop.
public with sharing class LazyLoadingController {
@AuraEnabled(cacheable=true)
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