Activity Forums Salesforce® Discussions How we can use a map in Salesforce Lightning Component?

  • Piyush

    Member
    September 24, 2019 at 3:39 am

    Hi,

    You can use a map in Salesforce Lightning Component like this :-

    <aura:component implements="forceCommunity:availableForAllPageTypes" access="global" controller="MyClass">
        <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
        <aura:attribute name="myMap" type="Map" />
    </aura:component>
    ({
       doInit: function(component, event, helper) {      
    
           var action = component.get('c.getMap');
            
            action.setCallback(this,function(result){
                component.set('v.myMap',result.getReturnValue());
            });
            $A.enqueueAction(action);
         }
    })
    public with sharing class MyClass
    {
          public static MAP<String,String> getMap()
          {
              Map<String,String> map = new Map<String,String>();
              map.put('key1','value1');
              map.put('key2','value2');
              return map;
          }
    }

    For more, you can take help from this URL.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos