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
Julien SalensonJulien Salenson 

lightning:dualListbox save bug

I have a very strange error.
I have developped a component with lightning:dualListbox.
I have a button 'enregistrer' in controller to save this ordered list (Call when I hit button Save)

But sometimes "enregistrer" return null after the call back on :
actionEnregistrer.setCallback(this, function(actionResult) {
...
if(actionResult.getReturnValue()==null){
service.showWarningToast('Le composant APEX ne répond pas, impossible de sauvegarder !');
}

The strange things is, if i open developper console in another tab, and go back to my component, it's working !
Very strange, isn't it ?

Well do you have an idea where this bug come from ?

Component is :
<lightning:dualListbox name="multipleOptions"  
                                       sourceLabel="Corbeille" 
                                       selectedLabel="Affiché" 
                                       options="{!v.listOptions}" 
                                       value="{!v.selectedOptions}"
                                       />


<lightning:button variant="brand" 
                                      iconName="utility:save" 
                                      label="Enregistrer"
                                      title="Enregistrer"
                                      onclick="{! c.enregistrer }"/>

Controller is :
enregistrer: function(component, event, helper) {
        let service = component.find('service');
        var selectedOptionValue = component.get("v.selectedOptions");//component.get("v.selectedArray");
        var typeObj = component.get("v.typeObj");
        if(selectedOptionValue!=null && typeObj!=null){
            console.log("Option selected with value: '" + selectedOptionValue.toString() + "'");
            var actionEnregistrer = component.get("c.doSaveOrder");
            actionEnregistrer.setParams({
                tabOrderedLine : selectedOptionValue,
                typeObj :typeObj
            });
            //Setting the Callback
            actionEnregistrer.setCallback(this, function(actionResult) {
                console.log('enregistrer:setCallback');
                console.log('actionResult:'+actionResult.getReturnValue());
                if(actionResult.getReturnValue()==null){
                    service.showWarningToast('Le composant APEX ne répond pas, impossible de sauvegarder !');
                }
                else{
                    var result=actionResult.getReturnValue()[0];
                    console.log('result:'+result);
                    var resultMessage=actionResult.getReturnValue()[1];
                    console.log('resultMessage:'+resultMessage);
                    //check if result is successfull
                    if(result=='0'){
                        console.log('avant showSuccessToast');
                        service.showSuccessToast(resultMessage);
                        console.log('apres showSuccessToast');
                        helper.clickBackToConfig(component, event);
                    } else{
                        service.showWarningToast('Erreur :'+resultMessage);
                    }
                }
            });
            //adds the server-side action to the queue        
            $A.enqueueAction(actionEnregistrer);
        }
        else{
            if(selectedOptionValue==null) service.showWarningToast('Impossible de charger la selection');
            else service.showWarningToast('Le type d\'objet n\'a pas été chargé :'+typeObj);
        }
    },

APEX is:
//Sauver l'odre des options 
    @AuraEnabled
    public static List<String> doSaveOrder(List<String> tabOrderedLine, String typeObj) {
        List<id> lIdSelected = new List<id>();
        List<String> ReturnString=new List<String>();
        List<score_setting_field_mapping__c> sco_field_map_toUpdate = new List<score_setting_field_mapping__c>();
        if(tabOrderedLine.size()>0){
            String debug = '';
            score_setting_field_mapping__c[] sco_field_map;
            //Perform Operation with records (cutted)
            update sco_field_map_toUpdate;
            ReturnString.add('0');
            ReturnString.add('Sauvegarde effectuée !');
            
        }
        else{
            ReturnString.add('1');
            ReturnString.add('Vous devez modifier l\'odre d\'au moins une ligne');
        } 
        return ReturnString;
    }

​​​​​​​