3

Is there any way to display Geolocation part of Address field type in edit or display mode?

Account object contains specific BillingAddress field of Address type (is in beta). Also, as mentioned here, Address field type contains Location part of Geolocation (latitude, longitude) and many more parts.

All parts are displayed on the Account Page Layout, but Location is hidden (see attachments). Does anybody know how to make it visible and editable?

enter image description here

3

I agree it is curious there is no obvious way to make this appear in the UI. So for now it is workarounds.

Visible is easy. A workaround could be to create a formula field that took the Lat/Long values and simply displayed them in string format.

TEXT(BillingLatitude) & " , " & TEXT(BillingLongitude)

To have them editable, there are a few ways, such as inline visualforce pages. But maybe a nice clean way would be link to a visualforce page and edit there. In this instance, a basic edit page might look as follows:

<apex:page standardController="Account" >
  <apex:form>
  <apex:pageBlock mode="edit">
    <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection>
        <apex:inputField value="{!Account.BillingLatitude}"/>
        <apex:inputField value="{!Account.BillingLongitude}"/>
    </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

Then you would change the formula field to add a link as follows:

TEXT(BillingLatitude) & " , " & TEXT(BillingLongitude) & " " & 
  HYPERLINK("apex/AccountGeolocation?id="&Id&"&retURL=%2f" & Id ,"(Change)", "_self")

And that gets you page flow that mirrors the user experience for editing ownership, and record type:

New Formula Field on UI

Geolocation Edit Page

There are certainly other bells and whistles you might want to add. For instance you could stick some Javascript in your geolocation page to use the geo api and get it from the device the user is using. But this should get you started.

  • Great solution! Thanks. But when I have a formula field it always has "0 , 0" value. Any ideas? – Adel Nazirov Sep 17 '14 at 12:31
  • Are you certain you have data in the lat/long fields? All your records will have 0,0 until you populate some data in those fields. – pchittum Sep 17 '14 at 15:11
  • Combining an IF() and ISNULL() you could modify the plain text part of the formula to have it display nothing if the Lat/Long fields are not set. If I can get back to it I'll add it in. – pchittum Sep 17 '14 at 22:37
  • All is fine. But I have another problem. Formula field is not displayed on Account Page in edit mode. I don't want it to be editable. The aim is Customer change its address and then geolocation will be changed in javascript. Is there any way to display location part in both display and edit mode? – Adel Nazirov Sep 19 '14 at 7:12
  • Formula fields do not show in edit mode I believe. This solution is not perfect. But given that the page is Visualforce, that would be the natural place to put the Javascript to capture geocoding in this solution. If you want to find out about geocoding in Visualforce, search the stack exchange here, and if you don't find a solution, post a new question. :-) – pchittum Sep 19 '14 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.