1

In my controller I query for leads and accounts to display them in a googlemap and also in a panelGrid:

enter image description here

However what I fail to achieve is to display the leads and accounts in the same panelGroup and not 2 single ones

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

So far I have 2 seperate queries. One for 'warehouse' (leads) and one for 'Pot' (accounts) - (here a snippet)

warehouses =  [ 
                           SELECT Id,Street,company, Name,
                           FROM Lead
                           WHERE DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput)
                          ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                           LIMIT :recordLimit
                  ];

pot = [ 
                           SELECT Name,ShippingCity,ShippingPostalCode
                           FROM Account
                           WHERE  DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput) 
                          ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                           LIMIT :recordLimit
           ];

Since I do not know any better I created for each an apex:PanelGrid in my visualforce page:

To Display Leads:

<apex:pageBlockSectionItem >
<apex:outputPanel styleClass="container-fluid">
<div style="height:300px; overflow:auto !important;"> 
<apex:repeat value="{!warehouses}" var="war">
<apex:panelGrid columns="2" columnClasses="col1, col2"> 
<apex:panelGroup >                           
<apex:variable var="url" value="GoogleDistance | https://www.google.com/maps?saddr=+ 
{!currentAccount.Geolocation__c}&daddr=+{!war.Geolocation__c}" />
<apex:outputLink rendered="{!IF(NOT(CONTAINS(selectedField,'Jobads')), true, false)}" value=" 
{!MID(url, FIND('|', url) + 1, LEN(url))}" target="_blank">{!distances[war.id]}</apex:outputLink>                 
</apex:panelGroup>                        
</apex:panelGrid>
</apex:repeat> 
</div> 
</apex:outputpanel>    
</apex:pageBlockSectionItem>

To Display Accounts:

<apex:pageBlockSectionItem >
<apex:outputPanel styleClass="container-fluid">
<div style="height:300px; overflow:auto !important;">  
<apex:repeat value="{!pot}" var="pote">                       
<apex:panelGrid columns="2" columnClasses="col1, col2"> 
<apex:panelGroup >
<apex:variable var="url" value="GoogleDistance | https://www.google.com/maps?saddr=+ 
{!currentAccount.Geolocation__c}&daddr=+{!pote.Geolocation__c}" />
<apex:outputLink rendered="{!IF(NOT(CONTAINS(selectedField,'Jobads')), true, false)}" value=" 
{!MID(url, FIND('|', url) + 1, LEN(url))}" target="_blank">{!distances[pote.id]}</apex:outputLink>  
</apex:panelGroup>                              
</apex:panelGrid>                 
</apex:repeat> 
</div> 
</apex:outputpanel>            
</apex:pageBlockSectionItem>

I have read some articles about wrapper classes but struggle to adapt this to my problem.

Can anyone point me in the right direction? To put leads and accounts in the same panelgrid instead of 2 seperate one for each objects?

Thanks!

1 Answer 1

0

You can use a Wrapper class to create a wrapper object that you can use a getter to return to visualforce.

Here is a pseudo-code to help you

public class yourControllerclass {
  public inherited sharing class PotWareHouseWrapper {

  public String name {get; set}

  public Id recordId {get; set}

  public String geoLocation {get; set}

    public PotWareHouseWrapper(String name, Id recordId, String geoLocation) {
     this.name = name;
     this.recordId = recorded;
     this.geoLocation = geoLocation;
   }
 }

 List<PotWareHouseWrapper> wrapperlist {get;set;}


  public void createWrapperlist() {

  wrapperlist = new List<PotWareHouseWrapper>();
  String myInput = '';

  for(Lead leadRec: [ SELECT Id,Street,company, Name, Geolocation__c
                       FROM Lead
                       WHERE DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput)
                      ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                       LIMIT :recordLimit
              ]) {
    PotWareHouseWrapper wareHouse = new PotWareHouseWrapper(leadRec.Name, leadRec.Id, leadRec.Geolocation__c);
    wrapperlist.add(wareHouse);

}

// Repeat same for Account here

for(Account accRec: warehouses =  [ 
                       SELECT Id,Street,company, Name, Geolocation__c
                       FROM Lead
                       WHERE DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput)
                      ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                       LIMIT :recordLimit
              ]) {
    PotWareHouseWrapper pot = new PotWareHouseWrapper(accRec.Name, accRec.Id, accRec.Geolocation__c);
    wrapperlist.add(pot);

    }
  }
}

Here is another example if you want to look into

You must log in to answer this question.

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