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 

How to pass map from lightening Component to apex Controller.

Controller

var dataMap = component.get("v.values");  
      //  console.log(accountId) ;
        var accountList = [];       
        for ( var key in dataMap ) {
            accountList.push({key: key, value:dataMap[key]});
        }
        console.log(accountList) ;        
        var action = component.get("c.updateSortOrder");
        // console.log(accountList) ;
        action.setParams({
            "updateTasksMap":accountList
        });  



AuraEnabled
    Public static void updateSortOrder(Map<string, List<Task__c>> updateTasksMap){ 
        System.debug(updateTasksMap.keyset()) ;
        
AbhinavAbhinav (Salesforce Developers) 
Hi Ramana,

You can go through below link. both have similar situation as of yours

https://stackoverflow.com/questions/41876959/how-to-send-javascript-map-as-a-parameter-from-lightning-component-to-apex-serve

https://salesforce.stackexchange.com/questions/157732/how-to-send-javascript-map-as-a-parameter-from-lightning-component-to-apex-serve

Hope it helps, Please mark it best answer so that other facing similar issue find it useful.

Thanks!
Suraj Tripathi 47Suraj Tripathi 47

hi,

 you can take references from the below code.

<aura:component controller="Your_Controller">
    <aura:attribute name="theMap" type="Map" default="{}"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
Controller code:

({
    doInit : function(component, event, helper) {
        var action = component.get("c.SaveBatchDet");
        var theMap = component.get("v.theMap");
        //add some params
        theMap["key1"]="test1,test2,test6";
        theMap["key2"]="test3,test4,test5";
        action.setParams({
           "RowIndex": theMap
        });
        action.setCallback(this, function(result) {} );
        $A.enqueueAction(action);
    }
})

Apex :

@AuraEnabled
public static list<batch__c> SaveBatchDet(map<string,list<batch__c>> RowIndex){
         system.debug('RowIndex'+RowIndex);
}
Ramana123Ramana123
Hi Suraj here we are adding Static,, in the sense passing test1, test2 values how we can add dynamically .
Ramana123Ramana123
Uncaught Action failed: c:TableGrouping$controller$drop *[dataMap.get is not a function] * *And getting this error*