Syntax Highlighter JS
Thursday, October 31, 2013
Halloween Treat: Source Code for Geocoding engine
Previously, I posted a managed package that contained a Geocoding engine which used Google Maps, Map Quest, or Bing.
As a Halloween treat, I am releasing the source code for that engine. You may use it in your projects only if you post any additions, updates, changes, etc back to a fork of the project on GitHub. This is so the community can benefit from our combined works.
This project is based off of the strategy design pattern and as such can be extended to use other APIs.
Once you get that up and running, don't for get my example of how to view the data in a mash-up which can be seen here.
Monday, August 5, 2013
Reporting on more than 3 objects without using formula fields
You get a request from a user to create a custom report type and you associate your 3 objects only to find that a field you want to report on isn't on one of these 3 objects.
So you create a formula field to pull in the data you want down to one of the 3 objects. New administrators and developers do it all of the time. It works and they move on with their work day.
Did you know there is another way to accomplish this without clogging your objects up with redundant fields?
Custom report types allow you to select up to 3 objects down stream from a primary object but did you know that you can go 4 levels back up from those objects? This gives you a total of about 20 objects you can pull fields from.
For this example, I am going to use the objects and data from the Survey Force app. This is free from Salesforce labs and can be found here.
Open the menu under your name and click
. Once on the setup screen, expand the
menu and select the
option.
In this example, we want to create a report that will show data from the survey, the question and the contact that completed the survey.
So select Surveys as your primary object, Survey's Taken as your secondary, and Survey Question Responses as your tertiary object. Your object relationships should now look like this:

Since we want to pull data from the contact object but it wasn't selected during this process, a lot of people get confused and assume that the data can't be pulled in without a formula field.
However, this is wrong. Save your report type and then click the
button.
Unless you have created a new custom field and are coming back in to add that new custom field to a preexisting custom report type, you have probably discounted this screen.
On the right side of the screen under the Legend you will see a box like this:

Select "Survey's Taken Fields" as seen in the screen shot and then click the "Add fields related via lookup" link below the text.
A box like this will now appear:

This is where you can select objects that were not originally selected but that have a relationship to those objects. For this example, select "Survey Taken By Contact" and you will see a window like this:

Select Account name, click ok and now your selected fields will include the Account Name:

Now you can add this field to reports that use this custom report type.
So you create a formula field to pull in the data you want down to one of the 3 objects. New administrators and developers do it all of the time. It works and they move on with their work day.
Did you know there is another way to accomplish this without clogging your objects up with redundant fields?
Custom report types allow you to select up to 3 objects down stream from a primary object but did you know that you can go 4 levels back up from those objects? This gives you a total of about 20 objects you can pull fields from.
For this example, I am going to use the objects and data from the Survey Force app. This is free from Salesforce labs and can be found here.
Open the menu under your name and click
In this example, we want to create a report that will show data from the survey, the question and the contact that completed the survey.
So select Surveys as your primary object, Survey's Taken as your secondary, and Survey Question Responses as your tertiary object. Your object relationships should now look like this:
Since we want to pull data from the contact object but it wasn't selected during this process, a lot of people get confused and assume that the data can't be pulled in without a formula field.
However, this is wrong. Save your report type and then click the
Unless you have created a new custom field and are coming back in to add that new custom field to a preexisting custom report type, you have probably discounted this screen.
On the right side of the screen under the Legend you will see a box like this:
Select "Survey's Taken Fields" as seen in the screen shot and then click the "Add fields related via lookup" link below the text.
A box like this will now appear:
This is where you can select objects that were not originally selected but that have a relationship to those objects. For this example, select "Survey Taken By Contact" and you will see a window like this:
Select Account name, click ok and now your selected fields will include the Account Name:
Now you can add this field to reports that use this custom report type.
Friday, May 3, 2013
New Managed Package for Geocoding
I have released an new managed package of the Geocoding engine.
This version has an application where you can see logs from past attempts as well as change some settings.
Due to the fact that Google enforces geocoding limits by IP address and those addresses are shared on the Salesforce platform, I have added support for Map Quest and Bing geocoding services.
These services will require you sign-up for a free or paid API Key that comes with its own limits, but those are based on the key and not the IP address.
On the settings screen, I have included a link to the sign-up page for each service.
05/06/13 Update #2 : The issues with accessing the custom settings and scheduling problems have been fixed and the updated managed package can be found here. Please install the new version (1.7) over any older editions.
This version has an application where you can see logs from past attempts as well as change some settings.
Due to the fact that Google enforces geocoding limits by IP address and those addresses are shared on the Salesforce platform, I have added support for Map Quest and Bing geocoding services.
These services will require you sign-up for a free or paid API Key that comes with its own limits, but those are based on the key and not the IP address.
On the settings screen, I have included a link to the sign-up page for each service.
05/06/13 Update #2 : The issues with accessing the custom settings and scheduling problems have been fixed and the updated managed package can be found here. Please install the new version (1.7) over any older editions.
Thursday, April 4, 2013
Managed package for Geocoding Account Addresses
05/03/13 Update: I have released a new version. As such, the previous package is no longer available.
Since I posted an example Google geocoding engine, many changes have occurred and some of those include:
To accommodate these changes, I have updated the engine and placed it inside of a managed package.
The managed package will automatically add the classes, fields, remote site, and schedule the updater to run at the top of each hour.
This updated engine also includes a trigger so that individual records can be geocoded upon insert or update.
Geocoding is now performed on both the Billing and Shipping addresses and the resulting data is placed in corresponding geolocation fields.
Click here to install the managed package.
Since I posted an example Google geocoding engine, many changes have occurred and some of those include:
- Google moved the geocoding API to a new URL
- Google dropped the API key requirement when V3 was released
- Salesforce has added geolocation fields to the platform.
To accommodate these changes, I have updated the engine and placed it inside of a managed package.
The managed package will automatically add the classes, fields, remote site, and schedule the updater to run at the top of each hour.
This updated engine also includes a trigger so that individual records can be geocoded upon insert or update.
Geocoding is now performed on both the Billing and Shipping addresses and the resulting data is placed in corresponding geolocation fields.
Thursday, March 7, 2013
Salesforce Google Maps (V3) mash-up
Since I posted my example of a Google maps mash-up on Salesforce, Google has changed the way version 3 of the maps API works. Unfortunately, these changes broke the previous example.
I have created a new example and here is what the page looks like now:
I have posted the code on Git Hub for easy downloading. The sample page and controller can be found here.
I have created a new example and here is what the page looks like now:
<apex:page sidebar="false" showHeader="false" cache="false" controller="GoogleMap_Accounts_Controller">
<style>
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
function initialize() {
// set the map options in the format that V3 of googlemaps expects
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(32.5206608,-86.80249),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// attach our map to the map_canvas div
map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
// Pull the data in from the SOQL and use visualforce to create the javascript calls
<apex:repeat value="{!AccountsList}" var="Account">
showAddress("{!JSENCODE(Account.Name)}", "{!JSENCODE(Account.Name)} <a href='../{!Account.id}' target='_blank'>Details</a>", "{!Account.BillingLat__c}", "{!Account.BillingLong__c}");
</apex:repeat>
} // function initialize()
google.maps.event.addDomListener(window, 'load', initialize);
function showAddress(title, content, Lat, Long) {
// convert our raw values to the format that google expects
var latlng = new google.maps.LatLng(parseFloat(Lat), parseFloat(Long));
if (latlng != null) {
// create an info window
var infowindow = new google.maps.InfoWindow({
content: content
});
// Create a marker on the map
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: title
});
// Add an event to the marker so the info window will appear when it is clicked
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} // check for null latlng due an error parsing
} // end show address
</script>
<div id="map_canvas" style="width: 100%; height: 100%"></div>
</apex:page>
I have posted the code on Git Hub for easy downloading. The sample page and controller can be found here.
Wednesday, February 20, 2013
Update: VF component for USPS address verification
Back in October I posted a Visual Force component that would contact the USPS (using your free account) to verify your address and give you a chance to correct or standardize it. This can be very handy when using Visual Force pages to enter leads into your system.
A few people commented that they could get this working in the test / sandbox system but that it would fail deployment to production with an System.CalloutException of "You have uncommitted work pending. Please commit or rollback before calling out".
This was very interesting because even the classes that were not making any DML statements (insert, update, etc) were causing this error to be thrown. I wasn't the only one who ran into this error as you can read about in this thread on the developer boards.
Salesforce has now fixed the deployment tool such that if you wrap the test methods (that use the mock functionality) with Test.StartTest() and Test.StopTest() you can now deploy to production directly.
Previously you had to use a complex scheme where you would rename the classes such that the mock callout classes were alphabetically first.
I have updated the source code on Git Hub and you can get it here. You should be able to directly deploy this to production with 100% code coverage.
A few people commented that they could get this working in the test / sandbox system but that it would fail deployment to production with an System.CalloutException of "You have uncommitted work pending. Please commit or rollback before calling out".
This was very interesting because even the classes that were not making any DML statements (insert, update, etc) were causing this error to be thrown. I wasn't the only one who ran into this error as you can read about in this thread on the developer boards.
Salesforce has now fixed the deployment tool such that if you wrap the test methods (that use the mock functionality) with Test.StartTest() and Test.StopTest() you can now deploy to production directly.
Previously you had to use a complex scheme where you would rename the classes such that the mock callout classes were alphabetically first.
I have updated the source code on Git Hub and you can get it here. You should be able to directly deploy this to production with 100% code coverage.
Subscribe to:
Posts (Atom)