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
Ramana123Ramana123 

Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://LighteningComponentControllerList/ACTION$updateStatus Failing descriptor: {markup://c:MyListCompone

I am Passing Values From VF page to Componnet , I want to dsiplay toaster message But it is showing the above Error :

VF Page : 

<apex:page standardController="Account" extensions="ListViewButtonController" recordSetVar="accs" >
    <apex:includeLightning /> 
    <script type="text/javascript">      
    var jsAccounts= new Array();
    <apex:repeat value="{!idsList}" var="accId">
        jsAccounts.push('{!accId}');
    </apex:repeat>   
    $Lightning.use("c:SampleApp", function() {
        $Lightning.createComponent("c:MyListComponent", 
                                   { "accountId" :jsAccounts},                                       
                                  );
                                   });   
        
        </script>
</apex:page>

Component :  

<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable" access="global" controller="LighteningComponentControllerList">
    <aura:attribute name="listofAccounts" type="set" />
    <aura:attribute name="accountId" type="List" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>


Controller :
({
    doInit : function(component, event, helper) {
        var accountId = component.get("v.accountId");        
        var ids=new Array();
        for (var i= 0 ; i < accountId.length ; i++){
            ids.push(accountId[i]);
        }        
        var idListJSON=JSON.stringify(ids);        
        var action = component.get("c.updateStatus");
        action.setParams({
            "idsListValues":idListJSON
        });   
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();            
            if(state === "SUCCESS") {               
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Succés",
                    "message": "helloo",
                    "type": "success"
                });
                toastEvent.fire(); 
            }                       
        });
        $A.enqueueAction(action);       
    }
})

 

Suraj Tripathi 47Suraj Tripathi 47
Hi Ramana,
Greetings!

Please post your apex class code.
There are some parameter problems with your apex method.
Make sure in updateStatus method, there should be only one parameter name idsListValues of String type, not List type. 

Thank you!
Regards,
Suraj Tripathi
Ramana123Ramana123
Thanks Tripathi, Here is My Apex code : public class LighteningComponentControllerList { @AuraEnabled public static void updateStatus(List idsListValues){ List listtoUpdate = new List() ; for(Account acc : [SELECT ID,Name,Rating from Account where Id in :idsListValues ]){ acc.Rating = 'Hot' ; listtoUpdate.add(acc) ; } update listtoUpdate ; } } the update is working fine , but the toaster is not working .
Ramana123Ramana123
Apex Code 
public class LighteningComponentControllerList {    
    @AuraEnabled
    public static void updateStatus(List<String> idsListValues){    
        List<Account> listtoUpdate = new List<Account>() ;
        for(Account acc : [SELECT ID,Name,Rating from Account where Id in :idsListValues ]){
         acc.Rating = 'Hot' ;   
         listtoUpdate.add(acc) ;   
        }  
        update listtoUpdate ;
    }
}
Suraj Tripathi 47Suraj Tripathi 47
public class LighteningComponentControllerList {    
    @AuraEnabled
    public static void updateStatus(String idsListValues){
        List<Object> jsonIdList = JSON.deserializeUntyped(idsListValues);
        List<String> idListObj = new List<String>();
        for(Object ob : jsonIdList) {
            idListObj.add((String)ob);
        }
        List<Account> listtoUpdate = new List<Account>() ;
        for(Account acc : [SELECT ID,Name,Rating from Account where Id in :idListObj]){
         acc.Rating = 'Hot' ;   
         listtoUpdate.add(acc) ;   
        }  
        if(!isttoUpdate.isEmpty()) {
        update listtoUpdate ;
    }
    }
}
If this helped you please mark it as the best answer.
Thank you!
Regards 
Suraj Tripathi.