Skip to main content

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 


Comments

  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

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

    ReplyDelete

Post a Comment

Popular posts from this blog

Avoid Duplicate Records Using Flow

In this blog post lets see how to avoid duplicate records in Salesforce using the powerful feature – Flow , As the word says, flow easily flows to fulfill the requirements with ease. ☺  Many think of appexchange solutions and source code to avoid the duplicate record in salesforce, But the method I'm going to explain here is completely different and very simple. It helps you to reduce your code and can easily rebuild for other objects with different field logic with simple clicks. Lets jump into the solution, we will use flow to check duplicate record logic and use apex trigger to initiate the Flow whenever a record is created or updated. Visual Work Flow : [Click] First we will create the Flow to check the duplicate records based on the name and store the result in the variable. In this example, we will use the Account object for the dupe check. Step 1  : Create a new visual flow with the Name ‘ DuplicateAccountCheck ' Step 2  : Click and drag the RecordLookup into t

Export records from List view – ListView API

As part of the Winter’15 release salesforce introduced the List View API features which helps us to get details and records of list views for an object. I was started exploring more about the List view API and trying to build an use case using that. So I searched about List View in the IdeaExchange site then found that many users are looking for a solution to export records to excel directly from the list view. I built a solution for that Idea, which helps user to download all the records directly from the List view for both standard and custom object. You don’t have to make any change in the code to use this functionality for different objects. All you need is to create a custom button for that object as mentioned below. Lets take an example for Account object 1. Go to Setup –> Accounts –> Buttons, Links and Actions 2. Click ‘New Button or Link' 3. Enter  Label, Name and select display type as ‘List Button’ 4. Content source as “Onclick Javascript” and paste the

Lightning Picklist Path Component

Create your custom path for picklist field in any standard and custom objects. The new lightning picklistpath component in Winter18 helps us to display the picklist field progress similar to the lightning path. The path is rendered as a horizontal bar with one chevron for each picklist item, this component doesn't have key fields or guidance information and doesn't display the mark complete button similar to the lightning path.  <lightning:picklistPath aura:id="picklistPath" recordId="{!v.recordId}" picklistFieldApiName="status" / > The picklist path will display the progress based on the recordId and picklistApiName attribute value. Specify the API name of the picklist field in the picklistAPIName attribute which you want to display in the page layout and specify the Salesforce record ID in the recordID attribute so it renders the current value for the field in the page.   In this example, the status field in the case object disp