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); } })", "answerCount": 4, "upvoteCount": 0, "datePublished": "2021-05-18T04:06:24.000Z", "author": { "@type": "Person", "name": "Yeturu Srikanth", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000E7UCRQA3", "affiliation": { "@type": "Organization", "name": "bigworks" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "public class LighteningComponentControllerList {         @AuraEnabled     public static void updateStatus(String idsListValues){         List jsonIdList = JSON.deserializeUntyped(idsListValues);         List idListObj = new List();         for(Object ob : jsonIdList) {             idListObj.add((String)ob);         }         List listtoUpdate = new List() ;         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.  ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4IohSAF", "datePublished": "2021-05-18T05:58:36.000Z", "author": { "@type": "Person", "name": "Suraj Tripathi", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000DARW3QAP", "affiliation": { "@type": "Organization", "name": "Cloud Analogy" } } } ] } }
Skip to main content

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);       

    }

})

 
4 respuestas
  1. 18 may 2021, 5:58

    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.

     
0/9000