+ Start a Discussion
Jason Okrepkie 1Jason Okrepkie 1 

Google Maps Error: Invalid field Candidate__r for SObject Position__c

I'm working on the Force.com workbook and in the Visualforce section the suggested code is to pull in a map using Yahoo maps that doesn't seem to work. I found some code for Google Maps and am trying to pull the map from Google Map and display it in a section inside the Position object. Below are the objects and my code. Any help is appreciated.

I have the following custom objects:
Employment Website
Job Application
Review (master object - Job Application)
Job Posting (master object - Position, Employment Website)

<apex:page standardController="Position__c">
This map shows the locations of candidates who have applied for the {!Position__c.Name} position.

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

$(document).ready(function() {

  var myOptions = {
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false

  var map;
  var marker;

  var geocoder = new google.maps.Geocoder();
  var address = "{! Position__c.Candidate__r.Street__c}, " + "{! Position__c.Candidate__r.City__c}, " + "{! Position__c.Candidate__r.State_Province__c}, " + "{! Position__c.Candidate__r.Zip_Postal_Code__c}";

  var infowindow = new google.maps.InfoWindow({
    content: "<b>{! Position__c.Candidate__r.First.Name__c}}, " + "{! Position__c.Candidate__r.Street__c}, " + "{! Position__c.Candidate__r.City__c}, " + "{! Position__c.Candidate__r.State_Province__c}, " + "{! Position__c.Candidate__r.Zip_Postal_Code__c}"

  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

        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{! Position__c.Candidate__r.First.Name__c}}"

        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
        google.maps.event.addListener(infowindow, 'closeclick', function() {


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

  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";


#map {
  font-family: Arial;
  line-height:normal !important;


<div id="map"></div>
It's look like you are missing the relatioship field for Candidate on Position Object.

You have to add the it.
Geoffrey J FlynnGeoffrey J Flynn
How are the Candidate and Position objects tied together?  Are they by chance tied together using the Job Application object?
Jason Okrepkie 1Jason Okrepkie 1
I created a lookup realtionship from Position to Candidate and still received the same error.
Jason Okrepkie 1Jason Okrepkie 1
Error was slightly different - Error: Invalid field First for SObject Candidate__c
{! Position__c.Candidate__r.First.Name__c} should be {! Position__c.Candidate__r.FirstName__c}
Geoffrey J FlynnGeoffrey J Flynn
Have you checked that your SOQL queries are working using something like Workbench?  The error is saying that you are missing the lookup relationship.  You can even check this by trying to create a formula field on the Position object to get the Candidate First Name and make sure you are taking the correct approach
Geoffrey J FlynnGeoffrey J Flynn
To follow up from Balaji's comment.
or is should be 
{! Position__c.Candidate__r.First_Name__c}
It depends how you named your fields
James LoghryJames Loghry
Your Visualforce page is utilizing the standard controller for Position__c.  By default, standard controllers don't return fields on relationships, such as Position__c.Candidate__r.FirstName__c.  In order to read these fields, you'll need to provide an Apex extension class (or a different controller), where you query the record for the Candidate's First Name field.