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
CuerdasCuerdas 

Variable does not exist... what is happening?

This is my code;

public with sharing class HandlerNavi {
   
        @AuraEnabled (cacheable = true)
            public static List<Evento__c> getEvento() {
                List<Evento__c> even = new List<Evento__c>();
                for(Evento__c event :[SELECT Id, Name, Fecha__c FROM Evento__c ORDER BY Fecha__c]){
                    if(event.Fecha__c >= Date.today()){    
                        listEventos.add(event);        
                    }    
                }
                return listEventos;
            }
}

What is happening?

force-app\main\default\classes\HandlerNavi.cls  Variable does not exist: listEventos (8:25)
force-app\main\default\classes\HandlerNavi.cls  Variable does not exist: listEventos (11:24)
Best Answer chosen by Cuerdas
AnkaiahAnkaiah (Salesforce Developers) 
Hi Andres,

You have declared the list variable as even and you were trying to add values to listEventos. you need to add values to even.

try with below.
public with sharing class HandlerNavi {
   
        @AuraEnabled (cacheable = true)
            public static List<Evento__c> getEvento() {
                List<Evento__c> even = new List<Evento__c>();
                for(Evento__c event :[SELECT Id, Name, Fecha__c FROM Evento__c ORDER BY Fecha__c]){
                    if(event.Fecha__c >= Date.today()){    
                        even .add(event);        
                    }    
                }
                return even ;
            }
}
If this helps, please mark it as best answer.

THanks!!


 

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Andres,

You have declared the list variable as even and you were trying to add values to listEventos. you need to add values to even.

try with below.
public with sharing class HandlerNavi {
   
        @AuraEnabled (cacheable = true)
            public static List<Evento__c> getEvento() {
                List<Evento__c> even = new List<Evento__c>();
                for(Evento__c event :[SELECT Id, Name, Fecha__c FROM Evento__c ORDER BY Fecha__c]){
                    if(event.Fecha__c >= Date.today()){    
                        even .add(event);        
                    }    
                }
                return even ;
            }
}
If this helps, please mark it as best answer.

THanks!!


 
This was selected as the best answer
CuerdasCuerdas
Oh shit! totally noob thing... best answer...