Skip to content

Instantly share code, notes, and snippets.

@induprasad
Created April 24, 2018 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save induprasad/f1f29d1ae39a9bf123ec0e69329106b2 to your computer and use it in GitHub Desktop.
Save induprasad/f1f29d1ae39a9bf123ec0e69329106b2 to your computer and use it in GitHub Desktop.
Apex class to retrieve cases, accounts and their status
global without sharing class LCC_CaseResults {
@AuraEnabled
public static List<CaseViewResults> getAllCases() {
LIST<Case> filteredCases = new LIST<Case>();
LIST<Account> filteredAccounts = new LIST<Account>();
LIST<CaseViewResults> results = new LIST<CaseViewResults>();
Map<String, Case> recordSet = new Map<String, Case>();
SET<String> accountIds = new SET<String>();
//Query to retrieve your cases
//PS: This is a generic query and you can filter it based on your requirement
filteredCases = [SELECT Id, CaseNumber, toLabel(Status), Account.Name, AccountId from Case
where AccountId!='' LIMIT 999];
for(Case record : filteredCases) {
recordSet.put(record.id, record);
accountIds.add(record.AccountId);
system.debug('Accounts are:::'+accountIds);
}
filteredAccounts =[Select id, name from account where id IN:accountIds LIMIT 2];
filteredCases = new LIST<Case>();
filteredCases.addAll(recordSet.values());
CaseViewResults record = new CaseViewResults();
record.cases = filteredCases;
record.accounts = filteredAccounts;
results.add(record);
return results;
}
//Wrapper class
public class CaseViewResults {
@AuraEnabled public LIST<Account> accounts;
@AuraEnabled public LIST<Case> cases;
public CaseViewResults() {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment