Search records within distance and create appointments on map – Salesforce

Screen Shot 2017-06-17 at 12.17.39 AM

Three steps activity :-

  1. Drop a pin anywhere on map.
  2. Enter distance (Radius) to search customer (Any object with Geolocation field)
  3. Select records and create task or any object records

How it is done

Google Map + AngularJS + Lightning Design System

Step 1 :-

Checkout this ng-map by Allen Kim Link , This map module map usage of Google map with AngularJs so simple and easy you will need only few lines of code to get started.

Step 2 :-

From your gmail Id create a project from google console, get your app key. Steps provided here . Earlier this step was not required but currently google changed its policy etc etc. You can read that on google.

Step 3 :-

Lets assume you have geo location field on any object, for this example I create Location field on account and populated with random coordinates. Now from map you will get the location from the dropped pin. Enter any distance pass these values to controller and query

    global static List<AccountWrapper> getAllAccountsWithInDistance(String latLng,Integer dist){
        List<AccountWrapper> wrapper = new List<AccountWrapper>();
        String query = 'SELECT Id,Name,Location__latitude__s, Location__longitude__s,BillingCity'+
                       'FROM Account'+
                       'WHERE DISTANCE(Location__c, GEOLOCATION('+latLng+'), \'km\') < '+dist;
        for(Account acc : Database.query(query)){
            wrapper.add(new AccountWrapper(acc));
        return wrapper;

And here is the code of the Visualforce Page and Controller Link


One thought on “Search records within distance and create appointments on map – Salesforce

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s