Location Based Activities - Lightning

The new summer’16 feature automatic geocode for the address helps to track your nearby prospects and clients but you can also able to create location-based activities for the account, lead or contact records. Let’s see how to create location-based activity records. In this, below example, I will use the account record geolocation to track my activity records. 

As a first step, set up the geocode clean rules - https://developer.salesforce.com/blogs/developer-relations/2016/07/making-salesforce-data-location-aware.html?language=en  Once you setup the rule then, geocodes are automatically added to existing accounts, contacts, and leads. New accounts, contacts, and leads get this information when they’re saved. 

Next, I have created custom checkbox field in activity object called ‘Remind me at a Location’. Enable the checkbox field when creating the activity record. This is to identify which task I want to see based on the current geo-location so this activity record will use the Account billing address geolocation in our custom page. 

Lightning component

Now let's create a lightning component to display the activity records based on the current location in the Salesforce1 mobile app or in the browser. The lightning component has two logics first to identify the current geolocation of the user and next display the account activity records which is nearby based on the current geo-location.

Getting current geolocation

When the page loads first the lightning controller will get the current geolocation of the user and assign it to the component attributes. Below the simple code to get the current geolocation in lightning components

Now we have the current geo-location of the user, using that geo information we can able to retrieve the account task records which is nearby 20 mi. The SOQL query to retrieve the task record is as follow

When the user opens the lightning page in the salesforce1 mobile or in the browser then it will display the only activity records which are nearby based on the account record geolocation.

You can deploy this component by clicking this below button 


  1. The article is really helpful, thank you for posting.

    Regarding list view I have a Question that, is there any possible way to update the List view describe using httpReq or metadata api

  2. Very Well, This is the best i have ever seen, you explain very well. Totally Impressive. VPS Hosting
    UK VPS Hosting


Post a Comment

Popular Posts