Map in Salesforce

By | March 3, 2020

Map

  1. It is key value pair.
  2. Key must be primitive data type and value may be primitive data types/Reference data type.
  3. Primitive data type are integer,decimal,string,id,Boolean,data…
  4. Only one key value is allowed to be null.

Syntax

Map<key,value> variablename = new map<key,value>();

  • Data is storing according to keys dictionary order.
  • keys are case sensitive

Methods

  1. Put(key,value);
  2. Set<key> keyset(); used to read all keys.
  3. Remove(key);
  4. Size();

Example

Map<string,integer> m = new map<string,integer>();

m.put(‘salesforce’, 200);

 m.put(‘codes’ 300);

system.debug(‘map values’ +m);

Leave a Reply

Your email address will not be published. Required fields are marked *