1

I have a apex class that queries for leads which I then display in a visualforce using apex:map to show where these leads are located. What I want to do now is to display also accounts in the same apex:map. So that not only leads are visible on the map but also accounts. Where do I start? Do I need 2 Apex classes? One VF page with 2 extensions? How do I display the fields of two Objects only once? For example Account.Name and Lead.Company? I am grateful for every hint. Below my code so far for leads:

Apex Class:

 public class FindNearbyPotentials {

 public List<Map<String,Double>> locations { get; private set; }

 public Account currentAccount {get;set;}

 public List <Geolocation__mdt> geolocation { get; set; }

 public boolean fcb { get; set; }

 public FindNearbyPotentials (boolean fcb) {
 this.fcb = fcb;
 }

 Public string myInput{
 get {     
 if(myInput == null){
 myInput = String.valueof(15);
 }
      return myInput;

 }
  set;
}

 public List<Lead> warehouses  {get; private set;} 


 public FindNearbyPotentials(ApexPages.StandardController stdController) {
    currentAccount  = [SELECT Id,Name,WZ_Buchstabe__c,WirtschaftszweigWZ08__c, WZ_Code_ebene_2__c,Mitarbeiternzahl_final__c,AD_MS_Rel_Anzahl_bez__c,GeoLocPosition__c,Geolocation__c,Accountinhaber_Text__c,Auftragseingangstyp__c,ShippingStreet,ShippingCity,ShippingPostalCode,URL_zum_CC__c FROM Account WHERE ID =: stdController.getID()];

}

  public String currentPosition { 
    get {
        if (String.isBlank(currentPosition)) {
            currentPosition = currentAccount.Geolocation__c; 

        }
        return currentPosition;
    }
    set; 
}

public String currentId { 
    get {
        if (String.isBlank(currentId)) {
            currentId = currentAccount.Id; 

        }
        return currentId;
    }
    set; 
}

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

public PageReference findNearbyPotentials() {


    String lat, lon, theaccId;       

    List<String> getcurrentId = currentId.split(':', 0);
    theaccId = getcurrentId[0].trim();

    List<String> latlon = currentPosition.split(',');
    lat = latlon[0].trim();
    lon = latlon[1].trim();

    Decimal dlat = decimal.valueOf(lat);
    Decimal dlon = decimal.valueOf(lon);


     Geolocation__mdt geolocation = [SELECT Distance__c, Limit__c,Last_Deal_in_Days__c FROM Geolocation__mdt];
     Decimal maxDistance = geolocation.Distance__c;
     Integer recordLimit = integer.valueOf(geolocation.Limit__c);
     Decimal lastDeal = geolocation.Last_Deal_in_Days__c;

  if(fcb == true) {

  warehouses =  [ 
                           SELECT Id,Street,company, Name,LocateCity__longitude__s, LocateCity__latitude__s,GeoLocPosition__c,WirtschaftszweigWZ08__c,AD_MS_Rel_Anzahl_bez__c,Data_Pool_AM__c,WZ_Code_ebene_2__c,AD_MS_Rel_Datum_Letzte_bez__c,JOB_Titel_letzte_bez_rel_Anzeige__c,Nicht_zugewiesene_Leadevents_Counter__c
                           FROM Lead
                           WHERE DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput) AND Data_Pool_AM__c = true
                           ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                           LIMIT :recordLimit
                  ];       
   }

   else{

    warehouses =  [ 
                           SELECT Id,Street,company, Name,LocateCity__longitude__s, LocateCity__latitude__s,GeoLocPosition__c,WirtschaftszweigWZ08__c,AD_MS_Rel_Anzahl_bez__c,Data_Pool_AM__c,WZ_Code_ebene_2__c,AD_MS_Rel_Datum_Letzte_bez__c,JOB_Titel_letzte_bez_rel_Anzeige__c,Nicht_zugewiesene_Leadevents_Counter__c
                           FROM Lead
                           WHERE DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput) AND WZ_Code_ebene_2__c= :currentAccount.WZ_Code_ebene_2__c AND Data_Pool_AM__c = true
                           ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                           LIMIT :recordLimit
                  ];       
          }         

    return null;
}

}

here my vf page:

<apex:pageBlock >

             <apex:pageBlockSection title=" {!warehouses.size} relevante Potenziale im Umkreis von {!myInput} km gefunden." columns="1" id="geomap"> 
          <apex:form style="width:100%">


        <apex:inputCheckBox id="filter1" disabled="{!currentAccount.WZ_Buchstabe__c = null}" value="{!fcb}">
    <apex:actionSupport event="onclick" action="{!findNearbyPotentials}" rerender="geomap"/>
    </apex:inputCheckBox>
    <apex:outputLabel for="filter1" value="Branche ignorieren" />


      <apex:inputText value="{!myinput}" style="width:60px"/>
      <apex:commandButton value="Umkreis anpassen" rerender="geomap" action="{!findNearbyPotentials}"/>

        </apex:form> 

        <apex:map width="100%" height="300px" mapType="roadmap" center="{!currentAccount.ShippingStreet},{!currentAccount.ShippingCity},{!currentAccount.ShippingPostalCode}" showOnlyActiveInfoWindow="false" >


         <apex:mapMarker title="{! currentAccount.Name }" position="{!currentAccount.ShippingStreet},{!currentAccount.ShippingCity},{!currentAccount.ShippingPostalCode}" icon="{!URLFOR($Resource.location)}"/> 

                      <apex:repeat value="{!warehouses}" var="war">
                <apex:mapMarker position="{!war.GeoLocPosition__c}" title="{!war.id}" 
                icon="{!IF(war.Nicht_zugewiesene_Leadevents_Counter__c > 0,URLFOR($Resource.mitle),URLFOR($Resource.ms_marker))}" >


                <apex:mapInfoWindow >

                 <apex:outputPanel layout="block" style="font-weight: bold;">
                 <apex:outputLink value="{! '/' + war.Id}">
                <apex:outputText >{! war.company }</apex:outputText>
                </apex:outputLink>
                </apex:outputPanel>


                <apex:outputPanel layout="block">
                <apex:outputText >{! war.Street }</apex:outputText>
                </apex:outputPanel>


                 <apex:outputPanel layout="block">
                <apex:outputText >{! war.WirtschaftszweigWZ08__c}</apex:outputText>
                </apex:outputPanel>


                <apex:outputPanel layout="block">
                <apex:outputText >Anzahl Anzeigen: {!war.AD_MS_Rel_Anzahl_bez__c}</apex:outputText>
                </apex:outputPanel>


                <apex:outputPanel layout="block">
                <apex:outputText value="{0, date, dd.MM.yyyy}"> <apex:param value="{!war.AD_MS_Rel_Datum_Letzte_bez__c}" /> </apex:outputText>
                </apex:outputPanel>


                <apex:outputPanel layout="block">
                <apex:outputText > Titel: {!war.JOB_Titel_letzte_bez_rel_Anzeige__c} </apex:outputText>
                </apex:outputPanel>

                </apex:mapInfoWindow>

                </apex:mapMarker>
            </apex:repeat>
        </apex:map>

    </apex:pageBlockSection>



</apex:pageBlock>

The result:

enter image description here

1 Answer 1

2

You just need to add another attribute for it, exactly the same as you did for warehouses. Population will also be similar.

public List<Lead> warehouses { get; private set; } 
public List<Account> accounts { get; private set; }

...

accounts = [SELECT ... FROM Account WHERE ...];
1
  • Thank you so much @Adrian. This was way easier than I expected. I just did the query for accounts and added a "second" section in my visualforce page for them.
    – Jan Tonnet
    Commented Apr 14, 2020 at 5:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .