Hello I am completely new with VF I am trying to pass some data from an Apex controller to a VisualForce. The situation is the next one I want to display in Google maps by using the Google Maps Api the addresses from three different objects, So I made this apex controller:
public class MapCECompleto_Controller {
public static PageReference getCompleteList(){
List<Object> recordsToReturn = new List<Object>();
List<SObject1> listOne = [SELECT Id,Direccion__c, Estado__c, Name FROM SObject1];
if(!listOne.isEmpty()){
for(SObject1 iItem: listOne){
if(iItem.Estado__c == HelperClass.ESTADO_ACTIVADO){
Map<String, Object> oneMap = new Map<String, Object>();
oneMap.put('Name', iItem.Name);
oneMap.put('Direccion', iItem.Direccion__c);
oneMap.put('Objeto', 'Object 1');
oneMap.put('Id',iItem.Id );
recordsToReturn.add(oneMap);
}
}
}
List<SObject2> listTwo = [SELECT Id,EstadoSolicitud__c,Direccion__c,, Name, FROM SObject2];
if(!listTwo.isEmpty()){
for(SObject2 iItem: listTwo){
if(iItem.EstadoSolicitud__c == HelperClass.ESTADO_NUEVA || iItem.EstadoSolicitud__c == HelperClass.ESTADO_EN_GESTION){
Map<String, Object> twoMap = new Map<String, Object>();
twoMap.put('Name',iItem.Name );
twoMap.put('Direccion', iItem.Direccion__c);
twoMap.put('Objeto','Object 2');
twoMap.put('Id',iItem.Id );
recordsToReturn.add(twoMap);
}
}
}
List<SObject3> listThree = [SELECT Id,Direccion__c, Name FROM SObject3 LIMIT 3];
if(!listThree.isEmpty()){
for(SObject3 iItem: listThree){
Map<String, Object> threeMap = new Map<String, Object>();
threeMap.put('Name', iItem.Name);
threeMap.put('Direccion',iItem.Direccion__c);
threeMap.put('Objeto','Object 3');
threeMap.put('Id',iItem.Id);
recordsToReturn.add(threeMap);
}
}
List<SObject4> listFour = [SELECT Id, Direccion__c, Name FROM SObject4 LIMIT 3];
if(!listFour.isEmpty()){
for(SObject4 iItem :listFour){
Map<String, Object> fourthMap = new Map<String, Object>();
fourthMap.put('Name', iItem.Name);
fourthMap.put('Direccion',iItem.Direccion__c);
fourthMap.put('Objeto','Object 4');
fourthMap.put('Id',iItem.Id);
recordsToReturn.add(fourthMap);
}
}
System.debug('recordsToReturn ------ '+ recordsToReturn);
return recordsToReturn;
}
}
So once I have this data in my recordsToReturn variable I want to pass this to the visualForce page. My VF is this one:
<apex:page controller="MapCECompleto_Controller">
<apex:pageBlock title="Transactions">
<head>
<script type="text/javascript" src="{!googleMapsApi}"></script>
<script type="text/javascript">
function initialize(){
var resultados = {!listaDatosCompletos}
console.log(resultados);
var myOptions= {
zoom: 20,
mapTypeId: google.maps.MapTypeId.HYBRID,
mapTypeControl: true
}
var geocoder = new google.maps.Geocoder();
console.log('aqui1');
console.log('resultados ---- ');
var map = new google.maps.Map(document.getElementById('map'), myOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
#map{
font-family: Arial;
font-size: 12px;
line-height: normal !important;
height: 500px;
background: transparent;
}
</style>
</head>
<body>
<div id='map'></div>
</body>
</apex:pageBlock>
</apex:page>
So I want that everytime the user finds this map to bring automatically this data like with the connectedCallback() method from LWC. The problem is that I have not found the way to pass the apex variable recordToReturn to the VisualForce Page. Could anybody help me? I would appreciate it. I have been hours and hours trying to solve this but I have had no success.