Created
October 17, 2012 18:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| , 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()); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error fixed - needed Status field in SOQL query, required for grouping in listview.