0

I have a pretty simple visualforce page where I'm trying to load a map with all the 'installs' (named Site_Assessment__c in code) for a loaded lead. I have a controller that extends the lead built with the code to pull in the Lead's PostalCode for a SOQL query to get all the installs in the Lead's zip, but I'm having trouble with the syntax to get the list of installs in the visualforce page and plot them as mapMarkers. I'm going to add infowindows with data from the 'installs' next so this will be a problem there as well. Here is the visualforce page:

<apex:page standardController="Lead" extensions="FindNearestInstallsController" docType="html-5.0" >
<apex:pageBlock >
    <!-- Map of the results -->
    <apex:pageBlockSection title="Installs" rendered="{!resultsAvailable}">
        <apex:map width="600px" height="400px" center="{!Lead.Street}, {!Lead.City}, {!Lead.State}, {!Lead.PostalCode}" zoomLevel="17">
            <apex:mapMarker title="{!Lead.FirstName}  {!Lead.LastName}" position="{!Lead.Street}, {!Lead.City}, {!Lead.State}, {!Lead.PostalCode}" >
                <apex:mapInfoWindow >
                    <apex:outputPanel >
                        <apex:outputText style="font-weight: bold">
                            <strong>Lead: {!Lead.FirstName}  {!Lead.LastName}</strong>
                            <p>{!Lead.Street}, {!Lead.City}, {!Lead.State}, {!Lead.PostalCode}</p>
                        </apex:outputText>
                    </apex:outputPanel>
                </apex:mapInfoWindow>
            </apex:mapMarker>
            <apex:repeat value="{!installs}" var="Contact_Address__c">
                <apex:mapMarker position="{!Contact_Address__c}"></apex:mapMarker>
            </apex:repeat>
        </apex:map>
    </apex:pageBlockSection>
</apex:pageBlock>

I'm trying to plot the repeating mapMarkers using the Contact_address__c as the position. And the controller that extends the standard Lead controller:

global class FindNearestInstallsController {

public List<Site_Assessment__c> installs { get; private set; }

private final Lead lead;

public FindNearestInstallsController(ApexPages.StandardController stdController) {
    this.lead = (Lead)stdController.getRecord();
}

public Boolean resultsAvailable {
    get {
        if(installs == Null) {
            return false;
        }
        return true;
    }
}

public PageReference findNearbyInstalls() {
    // SOQL query to get the installs in postal code
    String queryString =
       'SELECT Id, Installation_Scheduled_End_Date__c,Opportunity_Name__c, System_Size__c, Postal_Code__c, Contact_Address__c ' +
       'FROM Site_Assessment__c ' +
       'LIMIT 10';

    // Run the query
    List <Site_Assessment__c> siteAssessments = database.Query(queryString);
    system.debug(siteAssessments);
    if(0 < siteAssessments.size()) {
        installs = new List<Site_Assessment__c>();
        for(Site_Assessment__c sa : siteAssessments) {
            installs.add(sa); 
        }
    }        
    return null;
    }
}
3

You never actually called "findNearbyInstalls", so your query never executes, and thus your installs list is empty. Your entire code can be distilled down to just a few lines of code:

public class FindNearestInstallsController {
    public List<Site_Assessment__c> installs { get; set; }
    public Boolean resultsAvailable { get; set; }
    final Lead leadRecord;

    public FindNearestInstallsController(ApexPages.StandardController stdController) {
        leadRecord = (Lead)stdController.getRecord();
        installs = [SELECT  Installation_Scheduled_End_Date__c, Opportunity_Name__c, 
                            System_Size__c, Postal_Code__c, Contact_Address__c
                    FROM    Site_Assessment__c
                    LIMIT   10];
        resultsAvailable = !installs.isEmpty();
    }
}

As for the actual records, you're trying to pass in an entire record, when you really wanted to put in addresses:

        <apex:repeat value="{!installs}" var="installRecord">
            <apex:mapMarker position="{!installRecord.Contact_Address__c}" />
        </apex:repeat>

Note: I've presumed that your code is simply incomplete, so I've left a few other things for you to fix as well. This should be enough to get you started.

| improve this answer | |
  • Thank you, I figured I was omitting something basic, I'll give this a shot. – ZackB Jul 6 '17 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.