Map Initialization Methods in APEX
Chapter Topics
- Apex Data Types
- Integer Data Type in APEX
- Floating Point Data Type in APEX
- String Data Type in APEX
- Date Datatypes in APEX
- Time and DateTime Data Types in APEX
- Boolean Datatype in Salesforce
- ID & Blob Datatypes in APEX
- What is the Rule of Conversions in Apex?
- Enums in APEX
- sObjects in Salesforce
- Generic sObjects in Salesforce
- Collections in APEX
- Lists in APEX
- List Array Notation in APEX
- Lists Initialization in APEX
- Nested Lists in APEX
- Sets in APEX
- Sets Initialization And Methods
- Maps in APEX
- Map Initialization Methods in APEX
- Operators in Apex and Their Types
- Shorthand Operator
- Equality Operator
- Relational Operators(<,>,<=,>=)
Initialisation of Maps in Apex
In Salesforce Apex, Maps are collections of key-value pairs, where each unique key maps to a single value. Initializing of Maps in Apex can be done in various ways depending on the requirements. Below are the different methods to initialize maps in Apex.
Empty Map Initialization
- Initialize an Empty Map of String to Integer:

- Initialize an Empty Map of ID to Custom Object:

Map Initialization with Values
- Initialize a Map with String Keys and Integer Values:

- Initialize a Map with String Keys and Custom Object Values:

Map Initialization with SOQL Query
Initialize a Map from a SOQL Query:

Map Methods in Apex
Following are the Map methods in Apex:

Join our newsletter: Get daily update on Salesforce career insights & news!
Join Now!
Need more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.