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
Eugenia PestelliEugenia Pestelli 

Uncaught Action failed: c:AccordianComponent$controller$doInit [Cannot read properties of null (reading 'Administration & Finance & Controlling Dept.')] Callback failed: apex://CodEsperApexCtrl/ACTION$getSettori

User-added image
hello everyone, I have a problem with this component, in addition to this error appearing, not always, but every now and then, I have these squares with objobj written inside on the display.

Can anyone help me figure out the error?


contenitore
<aura:component controller="SezioniApexCtrl" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    
   
    
    <aura:handler event="c:AggiungiPadre" action="{!c.AggiungiPadre}"/>
    <aura:handler event="c:SettoriEvent" action="{!c.AggiungiValSel}"/>
    
    <aura:handler event="c:TogliNipoti" action="{!c.TogliNipote}"/>
    <aura:handler event="c:TogliPadre" action="{!c.TogliPadre}"/>
    
     <aura:attribute name="SettoreUno_Salvato" type="String"/>
     <aura:attribute name="SettoreDue_Salvato" type="String"/>
    
    <aura:attribute name="ListSet" type="String[]"/>
    <aura:attribute name="MappaNonniFigli" type="map"/>
    <aura:attribute name="MappaFigliNipoti" type="map"/>
    
    <aura:attribute name="recordId" type="String"/>
    <aura:attribute name="MappaPerTracciareSelezioni" type="Map" default="{}"/>
    <aura:attribute name="StringaPerTracciareSelezioni" type="String[]" />
    <lightning:spinner aura:id="mySpinner" size="large" />
    <lightning:accordion activeSectionName="B">
        <aura:iteration items="{!v.ListSet}" var="Nonno">
            <c:AccordianComponent Mylabel="{!Nonno}" MappaNonniFigli="{!v.MappaNonniFigli}" MappaFigliNipoti="{!v.MappaFigliNipoti}"
                                   MappaPerTracciareSelezioni="{!v.MappaPerTracciareSelezioni}" SettoreUno_Salvato="{!v.SettoreUno_Salvato}"
                                  SettoreDue_Salvato="{!v.SettoreDue_Salvato}"  />
        </aura:iteration>
    </lightning:accordion>
    
     <ui:button label="Save Sectors" press="{!c.saveField}"/>
</aura:component>
component

<aura:component >
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    
    <aura:attribute name="Mylabel" type="String"/>
    <aura:attribute name="MappaNonniFigli" type="map"/>
    <aura:attribute name="MappaFigliNipoti" type="map"/>
    <aura:attribute name="ListFigli" type="String[]"/>
    
    <aura:attribute name="SettoreUno_Salvato" type="String"/>
    <aura:attribute name="SettoreDue_Salvato" type="String"/>
    
    <aura:attribute name="MappaPerTracciareSelezioni" type="Map" default="{}"/>
    
     
    <lightning:accordionSection aura:id="First" name="First_Set" label="{!v.Mylabel}" >
        <aura:iteration items="{!v.ListFigli}" var="Figlio">
            <c:FirstInputComponent Mylabel="{!Figlio}" MappaFigliNipoti="{!v.MappaFigliNipoti}" 
                                   MappaPerTracciareSelezioni="{!v.MappaPerTracciareSelezioni}" SettoreUno_Salvato="{!v.SettoreUno_Salvato}"
                                   SettoreDue_Salvato="{!v.SettoreDue_Salvato}" />
            <br>
            
            </br>
        </aura:iteration>
    </lightning:accordionSection>
</aura:component>

controller

({
    doInit : function(component, event, helper) {
        var map = component.get("v.MappaNonniFigli");
        var key =  component.get("v.Mylabel");
        console.log("***map: "+map);
        console.log("***key: "+key);
        console.log("***ListFigli: "+JSON.stringify(map[key]));
        component.set("v.ListFigli",map[key]);
    }
})

apexcode
public with sharing class SezioniApexCtrl {
    
    
    @AuraEnabled
    public static List<string> getSettori() {
        
        List<string> Settori = new List<string>();
        set<string> sett = new set<string>();
        For(Settore__c s: Settore__c.getall().values()){
            sett.add(s.First_Set__c);
        }
        for(string s:sett){
            Settori.add(s);
        }
        
        Settori.sort();
        system.debug('sett: '+Settori);
        
        
        return Settori;
    }
    
    @AuraEnabled
    public static Map<string, list<string>> getSecondSet() {
        
        map<String, list<string>> m1= new  map<String, list<string>>();
        
        For(Settore__c s: Settore__c.getall().values()){
            if(m1.get(s.First_Set__c) == null)
                m1.put(s.First_Set__c,new list<string>());
            set<string> st=new set<string>(m1.get(s.First_Set__c));
            if(!st.contains(s.Second_Set__c))
                m1.get(s.First_Set__c).add(s.Second_Set__c);
        }
        
        system.debug('Mappa: '+m1);
        
        return m1;       
        
    }
    
    @AuraEnabled
    public static Map<string, list<string>> getThirdSet(){
        
        map<String, list<string>> m2= new  map<String, list<string>>();
        
        For(Settore__c s: Settore__c.getall().values()){
            if(m2.get(s.Second_Set__c) == null)
                m2.put(s.Second_Set__c,new list<string>());
            m2.get(s.Second_Set__c).add(s.Third_Set__c);
        }
        
        return m2;
        
    }
    
    @AuraEnabled
    public static void  saveSett (string MyMap, String AccId){

        
        // Map<String, Object> MappaSelezioni = (Map<String, Object>)JSON.deserializeUntyped(MyMap);
        Map<String, List<String>> MappaSelezioni = (Map<String,List<String>>) JSON.deserialize(MyMaP, Map<String,List<String>>.class);
        
        String Nipoti = '';
        String Padri='';
        String Nonni='';
        Set<String> NonniSenzaDoppioni=new Set<String>();
        
        For(String s :MappaSelezioni.keySet()){
            Padri += s+';';
            For(string l: MappaSelezioni.get(s)){
               Nipoti += l + ';';
            }
        }
        system.debug('****Nipoti: '+Nipoti);
        List <account> aziende= new List<account>([SELECT id,Macro_Settore__c, SottoSettore1__c, Sottosettore2__c from Account where id =: AccId Limit 1]);
        if(aziende!=null && aziende.size()>0){
            List<Settore__c> MacroSettori=new List<Settore__c>([SELECT First_Set__c from Settore__c where Second_Set__c =:MappaSelezioni.keySet()]);
            
            For(Settore__c n : MacroSettori){ NonniSenzaDoppioni.add(n.First_Set__c);}
            For(String m : NonniSenzaDoppioni){ Nonni += m + ';'; }
            
            For(account a:aziende){
                a.Sottosettore1__c = Padri;
                a.Sottosettore2__c = Nipoti;
                a.Macro_Settore__c = Nonni;
                update a;}
        }
        }
    
    @AuraEnabled
    public static Map<String,String> AggiornaListaSelezionata (String mappaStringataFigliNipoti){
        String stringaFigliNipoti='';
        Map<String,String> mappaSelezioni=new Map<String,String>();
        
        return mappaSelezioni;
    }
    
    //AGGIUNTA
    @AuraEnabled
    public static List<String>  PopolaCheckFigli (String AccId){
        system.debug('AccId:   ****'+AccId);        
        Set<String> SetConSelezioni=new Set<String>();
        Set<String> SetConSelezioniNipoti=new Set<String>();
        List<String> ListaConSelezioni=new List<String>();
        List<String> ListaConSelezioniNipoti=new List<String>();
        
        List<Account> AccountGiaMemorizzato= new List<Account>([SELECT SottoSettore1__c from Account where id =: AccId]);
           
        For(Account a : AccountGiaMemorizzato){
            SetConSelezioni.add(a.SottoSettore1__c);
        }
        system.debug('SetConSelezioni  '+SetConSelezioni);
        
        For(String s : SetConSelezioni){
            ListaConSelezioni.add(s);
        }
        
        return ListaConSelezioni;
        
    }
    
    @AuraEnabled
    public static List<String>  PopolaCheckNipoti (String AccId){
        system.debug('AccId:   ****'+AccId);        
        
        Set<String> SetConSelezioniNipoti=new Set<String>();
        List<String> ListaConSelezioniNipoti=new List<String>();
        
        List<Account> AccountGiaMemorizzato= new List<Account>([SELECT SottoSettore2__c from Account where id =: AccId]);
        
       
        
        For(Account a : AccountGiaMemorizzato){
            SetConSelezioniNipoti.add(a.SottoSettore2__c);
        }
        system.debug('SetConSelezioni  '+SetConSelezioniNipoti);
       
        For(String s : SetConSelezioniNipoti){
            ListaConSelezioniNipoti.add(s);
        }
        
        return ListaConSelezioniNipoti;
        
    }
    
    @AuraEnabled
    public static Map<String, List<String>>  PopolaMappaIniziale (String AccId){
        system.debug('AccId:   ****'+AccId);        
        
        Map<String, List<String>> MappaDatiSalvati=new Map<String, List<String>>();
        List<String> NipotiSave= new List<String>();
        List<String> FigliSave= new List<String>();
        List<String> NipotiSaveList= new List<String>();
        
        List<Account> AccountGiaMemorizzato= new List<Account>();
        AccountGiaMemorizzato=[SELECT SottoSettore1__c, SottoSettore2__c from Account where id =: AccId];
        if(AccountGiaMemorizzato!=null && AccountGiaMemorizzato.size()>0){
            for(account a:AccountGiaMemorizzato){
               if(String.isNotBlank(a.SottoSettore1__c) && a.SottoSettore1__c.contains(';')) FigliSave=(a.SottoSettore1__c).split(';');
               if(String.isNotBlank(a.SottoSettore2__c) && a.SottoSettore2__c.contains(';')) NipotiSave=(a.SottoSettore2__c).split(';');}}
        
  
         map<String, list<string>> m2= new  map<String, list<string>>();
        
        For(Settore__c s: Settore__c.getall().values()){
            if(m2.get(s.Second_Set__c) == null && String.isNotBlank(s.Third_Set__c))
                m2.put(s.Second_Set__c,new list<string>());
            m2.get(s.Second_Set__c).add(s.Third_Set__c);
        }
        
        for(String s: FigliSave){
            for(String s2 : NipotiSave){
                if((m2.get(s)).contains(s2)){
                   NipotiSaveList.add(s2);
                }
            }
            MappaDatiSalvati.put(s,NipotiSaveList);
        }
            
       
        system.debug(' Mappa Dati Salvati: '+MappaDatiSalvati);
        return MappaDatiSalvati;
        
    }
    //AGGIUNTA
    
}
User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Is this complete code. Can you confirm where are you calling the apex controller from. I dont see any logic in Aura controller and don't see Helper at all.

Thanks,