Newer Version Available

This content describes an older version of this product. View Latest

Creating the Custom Controller

The Salesforce app supersedes Salesforce Mobile Classic. The Salesforce Classic Mobile app will retire on all supported platforms and devices on December 1, 2017. Customers should transition their users to the Salesforce for Android or iOS or deploy custom mobile apps to address their existing and future mobile needs.

Important

To build the mapping application, we first need to create the custom controller referenced by the Visualforce page that displays the map and corresponding list of accounts. The controller retrieves the user's accounts with a rating of 'Hot' and builds a string array of delimited accounts for use in the mapping JavaScript routine on the Visualforce page. It also defines a getter method for the Maps API key, which is required in order to use Google Maps in our page.

The following Apex class is the controller for the Visualforce page that maps the user's hot accounts:

1public class mapController {
2
3   public String addrStr;
4   public User usr;
5   public String myKey;
6
7   public Account[] getMyAccts() {
8      String usrId = UserInfo.getUserId();
9      Account[] accts = [Select Id, Name, Rating, CustomerPriority__c, 
10                         OwnerId, BillingStreet, BillingCity, BillingState, 
11                         BillingPostalCode
12                         From Account 
13                         where Rating = 'Hot'
14                         And OwnerId =: usrId ];
15                            
16      for(Account acct : accts) {            
17         addrStr = addrStr + acct.Name + ' : ' 
18                   + acct.CustomerPriority__c  + ':' 
19                   + acct.Id + '~:~'+ acct.BillingStreet + '~:~' 
20                   + acct.BillingCity + '~:~' +  acct.BillingState + '~:~' 
21                   + acct.BillingPostalCode + '~::~';		
22      }
23
24      return accts;     
25   }
26    
27   public String getmyKey() {  // Set up google maps api key
28      myKey = 'http://maps.google.com/maps?file=api&v=2&';
29
30      // In the following line, enter your google maps key
31      // to get an api key, visit the Google Maps API site
32      // http://code.google.com/apis/maps/signup.html
33      myKey = myKey + 'key=<insert_google_maps_api_key_here>';
34
35      return myKey;
36   }
37    
38   public String getAddrArStr(){
39      addrStr = '';
40      Account[] theRecs = getMyAccts();
41
42      return addrStr;	
43   }
44
45}