Skip to content

Instantly share code, notes, and snippets.

@forcementor
Created October 17, 2012 18:34
Show Gist options
  • Select an option

  • Save forcementor/3907256 to your computer and use it in GitHub Desktop.

Select an option

Save forcementor/3907256 to your computer and use it in GitHub Desktop.
Developing Mobile Applications with Force.com and Sencha Touch - Part 1, Step 7: Replace Your Mock Data With The Real Thing - Apex Controller
public class PocketCRMLeadController {
private string leads;
//Constructor.
public PocketCRMLeadController() {
//Fetch a limited set of Leads to return to the Sencha Data Store on load.
List < Lead > leadsList = [SELECT
FirstName
, LastName
, Company
, Title
, Phone
, Email
, Status
FROM Lead LIMIT 25];
//Serialize the list as JSON and assign to the private string member.
leads = JSON.serialize(leadsList);
system.debug('Leads as JSON: ' + leads);
}
//Public getter method to return the Leads as JSON to the view.
public String getLeads() {
return leads;
}
//UnitTest for code coverage.
testMethod static void canTestConstruction() {
//Build some mock data for the test.
List < Lead > leadList = new List < Lead > ();
for (Integer i = 0; i < 10; i++) {
leadList.add(new Lead(
Firstname = 'Test', Lastname = 'Lead' + String.valueOf(i), Company = 'Acme', Status = 'Open - Not Contacted'));
}
//Insert mock leads
INSERT leadList;
//Instantiate the controller which will fetch the Leads.
PocketCRMLeadController c = new PocketCRMLeadController();
system.assertNotEquals(c.getLeads(), null);
//Output to the debug for visual confirmation during testing.
system.debug(leadList);
system.debug(c.getLeads());
}
}
@forcementor

Copy link
Copy Markdown
Author

Error fixed - needed Status field in SOQL query, required for grouping in listview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment