Thursday, October 30, 2014

Easy Maps for Account and Contact Addresses in Salesforce

Some time ago, Salesforce had to remove their "Google Maps for Salesforce" from the App Exchange due to a change in Google's Licencing arrangements.

I've not seen a good example of easy to use Google Maps in Salesforce since, so here are some Custom Field Formulas. Simply create a new Custom Field with a Forumla -> Text type, and copy/paste the below into the formula area. On the page layout, it works really well below the address entry areas.



Each of these will display a static image map inline in Salesforce, and once the user clicks on the map, it will automatically display directions from the User's Address (stored on their User Profile) to that location. It will also complain to the user if they do not have an address on their profile, and will not display the Maps until they do.

Account Billing Address

if(or( $User.Street = "",  $User.City = "",  $User.Country  = ""),IMAGE("/img/samples/flag_red.gif", "red", 12, 12) + " Please Update "+HYPERLINK("/_ui/core/userprofile/UserProfilePage", "Your Profile")+" to include your Street, City and Country to see the map",

if(or(BillingStreet = "", BillingCity ="", BillingCountry =""), "Please Enter the Billing Address, Suburb and Country to see the Map.",

HYPERLINK("https://maps.google.com/maps?saddr="+ $User.Street +","+ $User.City +","+ $User.State +" "+ $User.Country +"&daddr="+ BillingStreet +", "+BillingCity +" "+ BillingState +" "+ BillingCountry +"&hl=en&t=m",

IMAGE("https://maps.googleapis.com/maps/api/staticmap?center="+ BillingStreet +","+ BillingCity +" "+BillingState+" "+BillingCountry +"&zoom=14&size=300x300&maptype=roadmap&markers=color:red%7C"+ BillingStreet +","+ BillingCity +" "+BillingState+" "+BillingCountry , 'Map'), "_Blank") + BR() + "Click to get Directions to this Address"
))

Account Shipping Address

if(or( $User.Street = "",  $User.City = "",  $User.Country  = ""),IMAGE("/img/samples/flag_red.gif", "red", 12, 12) + " Please Update "+HYPERLINK("/_ui/core/userprofile/UserProfilePage", "Your Profile")+" to include your Street, City and Country to see the map",

if(or(ShippingStreet = "", ShippingCity ="", ShippingCountry =""), "Please Enter the Shipping Address, Suburb and Country to see the Map.",

HYPERLINK("https://maps.google.com/maps?saddr="+ $User.Street +","+ $User.City +","+ $User.State +" "+ $User.Country +"&daddr="+ ShippingStreet +", "+ShippingCity +" "+ ShippingState +" "+ ShippingCountry +"&hl=en&t=m",

IMAGE("https://maps.googleapis.com/maps/api/staticmap?center="+ ShippingStreet +","+ ShippingCity +" "+ShippingState+" "+ShippingCountry +"&zoom=14&size=300x300&maptype=roadmap&markers=color:red%7C"+ ShippingStreet +","+ ShippingCity +" "+ShippingState+" "+ShippingCountry , 'Map'), "_Blank") + BR() + "Click to get Directions to this Address"
))

Contact Mailing Address

if(or( $User.Street = "",  $User.City = "",  $User.Country  = ""),IMAGE("/img/samples/flag_red.gif", "red", 12, 12) + " Please Update "+HYPERLINK("/_ui/core/userprofile/UserProfilePage", "Your Profile")+" to include your Street, City and Country to see the map",

if(or(MailingStreet = "", MailingCity ="", MailingCountry =""), "Please Enter the Mailing Address, Suburb and Country to see the Map.",

HYPERLINK("https://maps.google.com/maps?saddr="+ $User.Street +","+ $User.City +","+ $User.State +" "+ $User.Country +"&daddr="+ MailingStreet +", "+MailingCity +" "+ MailingState +" "+ MailingCountry +"&hl=en&t=m",

IMAGE("https://maps.googleapis.com/maps/api/staticmap?center="+ MailingStreet +","+ MailingCity +" "+MailingState+" "+MailingCountry +"&zoom=14&size=300x300&maptype=roadmap&markers=color:red%7C"+ MailingStreet +","+ MailingCity +" "+MailingState+" "+MailingCountry , 'Map'), "_Blank")+ BR() + "Click to get Directions to this Address"
))

Contact Other Address

if(or( $User.Street = "",  $User.City = "",  $User.Country  = ""),IMAGE("/img/samples/flag_red.gif", "red", 12, 12) + " Please Update "+HYPERLINK("/_ui/core/userprofile/UserProfilePage", "Your Profile")+" to include your Street, City and Country to see the map",

if(or(OtherStreet = "", OtherCity ="", OtherCountry =""), "Please Enter the Other Address, Suburb and Country to see the Map.",

HYPERLINK("https://maps.google.com/maps?saddr="+ $User.Street +","+ $User.City +","+ $User.State +" "+ $User.Country +"&daddr="+ OtherStreet +", "+OtherCity +" "+ OtherState +" "+ OtherCountry +"&hl=en&t=m",

IMAGE("https://maps.googleapis.com/maps/api/staticmap?center="+ OtherStreet +","+ OtherCity +" "+OtherState+" "+OtherCountry +"&zoom=14&size=300x300&maptype=roadmap&markers=color:red%7C"+ OtherStreet +","+ OtherCity +" "+OtherState+" "+OtherCountry , 'Map'), "_Blank")+ BR() + "Click to get Directions to this Address"
))