3 Fields Every Sales Organization Needs

Chad SmithUncategorized

Whether you’re dealing with Leads, Accounts or Opportunities keeping in touch with the folks associated with each is key to a successful sales organization.  Salesforce provides a rather odd field called ‘Last Activity’ for leads, accounts, and opportunities that is the last date an activity was conducted with the entity.

It’s odd because, while it’s available for user in list views and reports it isn’t available to place on the entity’s screen.

Last Activity 1

So this is a great field, but by using it in a formula field to calculate Days Since Last Activity is more useful as it can be used everywhere in Salesforce and lets you easily create reports and views such as Open Opportunities with No Activity in 30 Days.

So, for opportunities, here’s what the formula field for Days Since Last Activity would look like:

Last Activity 2

That formula would be the same for leads and accounts as well, you’d just need to create formula fields for those objects.

You can place it anywhere on the page layout but here you can see it as it would be displayed within the System Information section.

Last Activity 3

For a report, you can set the filter criteria so that you’re seeing all opportunities that have a Days Since Last Activity as greater than 30 or blank so you pick up  both.

Last Activity 4

Why you should never click the ‘Log a Call’ button in Salesforce

Chad SmithSalesforce Tips

This seems counter-intuitive, right? The CRM mantra is, “If it isn’t in Salesforce it didn’t happen.”

Well, you should still log your calls in Salesforce, but instead of using the Log a Call button in the history related list, we should be using the Quick Action in Chatter.

Quick Action
That is accessed from the Chatter Feed, then More and Log A Call.  Easy, enough, but why?  If you use the Log a Call, the activity certainly gets tracked, but unless someone views the record or runs a report they’re probably  not going to know that it happened.  If we use the Chatter Quick Action then it’ll also be in the chatter feed so anyone that follows that record will see it in their chatter feed and part of their daily digest.

The call will show in the chatter feed and in the activity history related list.

Quick Action 2a>

Apex Tip: How to get a RecordType Id by without SOQL

Chad SmithApex

Instead of using this:

[Select id from RecordType where sObjectType = 'Account' and developerName ='Customer'].id

Use this:

Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer').getRecordTypeId()

This can help avoid those pesky SOQL governor limits.

Add Embedded Google Maps on Leads, Accounts, and Contacts

Chad SmithSalesforce Tips, Visualforce

Here’s how we can get a very nice looking Google map tied to the current Lead, Account, or Contact that you are currently viewing.

 

Saleforce Google Map 1

First create a new Visualforce page (Setup > Develop > Page) for each of the types, here is the code for each:

Leads:

<apex:page standardController="Lead">
<apex:pageBlock >
<head>

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript"> 

$(document).ready(function() {

  var myOptions = {
    zoom: 20,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true
  }

  var map;
  var marker;

  var geocoder = new google.maps.Geocoder();
  var address = "{!Lead.Street}, " + "{!Lead.City}, " + "{!Lead.Postalcode}";

  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Lead.Name}</b>"
  });

  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {

        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        //center map
        map.setCenter(results[0].geometry.location);

        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Lead.Name}"
        });

        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition());
        });

      }

    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Lead.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });

  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }

});
</script>



<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:500px;
  background:transparent;
}
</style>



</head>

<body>


<div id="map"></div>


</body>
</apex:pageBlock>
</apex:page>

Accounts:

<apex:page standardController="Account">
<apex:pageBlock >
<head>

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript"> 

$(document).ready(function() {

  var myOptions = {
    zoom: 20,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true
  }

  var map;
  var marker;

  var geocoder = new google.maps.Geocoder();
  var address = "{!Account.BillingStreet}, " + "{!Account.BillingCity}, " + "{!Account.BillingPostalcode}";

  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Account.Name}</b>"
  });

  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {

        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        //center map
        map.setCenter(results[0].geometry.location);

        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Account.Name}"
        });

        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition());
        });

      }

    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Account.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });

  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }

});
</script>



<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:500px;
  background:transparent;
}
</style>



</head>

<body>


<div id="map"></div>


</body>
</apex:pageBlock>
</apex:page>

Contacts:

<apex:page standardController="Contact">
<apex:pageBlock >
<head>

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript"> 

$(document).ready(function() {

  var myOptions = {
    zoom: 20,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true
  }

  var map;
  var marker;

  var geocoder = new google.maps.Geocoder();
  var address = "{!Contact.MailingStreet}, " + "{!Contact.MailingCity}, " + "{!Contact.MailingPostalcode}";

  var infowindow = new google.maps.InfoWindow({
    content: "<b>{!Contact.Name}</b>"
  });

  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {

        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        //center map
        map.setCenter(results[0].geometry.location);

        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Contact.Name}"
        });

        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition());
        });

      }

    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! {!Contact.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });

  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }

});
</script>



<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:500px;
  background:transparent;
}
</style>


</head>
<body>


<div id="map"></div>


</body>
</apex:pageBlock>
</apex:page>

Then you’ll want to go to the page layout for each of the objects.  Create a new section that’ll hold the map.

Salesforce Google Map 2

Then add the Visualforce page to that section.  You can adjust the size of the map by changing the settings of the Visualforce page by using the wrench icon after it’s been dropped onto the layout.

 

Salesforce Google Map 3