function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Paul S.Paul S. 

Map location of all contact records relate to the same account

I'm trying to add a Visualforce map that will display the location of all contacts related to the same account, but I want to add the map to the contact record.  In other words, whenever I view a contact record I'd like to also see the location of not only that account, but of all other contact related to that same account.  

I'm pretty sure I need a custom contoller to make this happen, and while I've started to try to piece one together I'm stuck on the logic that will pull only the contacts related to the same account as the contact currently being viewed.  Hope that makes sense.

Controller:
public with sharing class relConController{ 

    Map<Id,Contact> relCont = new Map<Id,Contact>([SELECT Id,AccountId FROM Contact WHERE Id = :ApexPages.currentPage().getParameters().get('Id')]);
    
    public List<Contact> Records {get; set;} 
    public List<Contact> CurrentRecord {get; set;}
    
    public relConController(){ 
        Records = [select Name, Id, AccountId, MailingStreet, MailingCity, MailingState from Contact]; 
        CurrentRecord = [select Name, Id, MailingStreet, MailingCity, MailingState from Contact WHERE ID = :ApexPages.currentPage().getParameters().get('Id')]; 
    }
}

Page:
<apex:page Controller="relConController">

  <!-- This page must be accessed with an Account Id in the URL. For example: 
       https://<salesforceInstance>/apex/NearbyContacts?id=001D000000JRBet -->
  
  <apex:pageBlock >
    
      <apex:map width="600px" height="400px" mapType="roadmap" zoomLevel="10" center="{!CurrentRecord[0].MailingStreet},{!CurrentRecord[0].MailingCity},{!CurrentRecord[0].MailingState}">
      
        <apex:repeat value="{!Records}" var="Record">
        
            <apex:mapMarker title="{! Record.Name }" position="{!Record.MailingStreet},{!Record.MailingCity},{!Record.MailingState}"/>
            
        </apex:repeat>
        
      </apex:map>
      
  </apex:pageBlock>

</apex:page>