🌐
S2 Labs
s2-labs.com › home › map initialization methods in apex
Map Initialization Methods In Apex | Salesforce Developer Tutorials
August 7, 2025 - Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Id, Name FROM Account WHERE Industry = 'Technology']); ... Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry ...
Rating: 4.8 ​ - ​ 2.4K votes
Discussions

Using Maps in Apex (beginner)
Sounds liek you don't have a grasp of what the differences are. These concepts are not unique to Apex. A list is an ordered sequence of items, like people waiting to get their number called. The thing is, one person can have more than one number assigned, so they can appear in the waiting list more than once. A set is almost like a list except it does not allow for a person to have more than one chance to be in the waiting list (so it only appears once on the whole waiting list) and it's not ordered, so doesn't matter what number the person got assigned to it. A map is a representation of the person waiting and it's number. That number is unique, so it's the key, the person assigned to the number is the value, so each entry of the map is a pair where you can't have two pairs with the same key. Where does it all make sense to use? Well, it depends on the use case. Let's say you want to check all the accounts of all the opportunities to get the account type, the account ID, the name and the opportunity Id and Opp name and export it to a csv so someone somewhere can analyze it. You do your SOQL query, get everything in a nice list and you output it into a nice excel sheet with a pretty header, mail it to the guy that requested it. You come up with this little piece of code: List lstOpp = [Select Id, AccountId, Account.Type from Opportunity]; String output = ''; for(Opportunity opp : lstOpp){ output+=opp.Id+','; output+=opp.AccountId+','; output+=opp.Account.Type+'\n'; } system.debug(output); A day later he replies: "hey! I'm noob at excel and there's duplicates here I don't know how to get rid of. Can you just send it to me without duplicates? Thanks!" You then think: Ok, I'll just add the Opportunities I get from the query and put it into a Set! That way, they get the information they want and no duplicates, right? Right!? Let's see... List lstopp = [Select Id, AccountId, Account.Type from Opportunity]; String output = ''; Set stOpp = new Set(); for(Opportunity opp : lstopp){ stOpp.add(opp); } for(Opportunity opp : stOpp){ output+=opp.Id+','; output+=opp.AccountId+','; output+=opp.Account.Type+'\n'; } system.debug(output); That't not right! My unique value is an opportunity... What I need is to have something that allows me to check if a certain Account is already added on the list I'm writting down on the CSV. Let's however see how this can be done by throwing a Map into the mix :) List lstopp = [Select Id, AccountId, Account.Type from Opportunity]; String output = ''; Map mapOppsByAccountId = new Map(); for(Opportunity opp : lstopp){ /* Notice what happens if you put the same key twice: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm#apex_methods_system_map */ mapOppsByAccountId.put(opp.AccountId,opp); } for(Id accountId : mapOppsByAccountId.keySet()){ Opportunity opp = mapOppsByAccountId.get(accountId); output+=opp.Id+','; output+=opp.AccountId+','; output+=opp.Account.Type+'\n'; } system.debug(output); Not the best example but I think it helps. If you have more questions (or if I made it even more complicated) let me know. More on reddit.com
🌐 r/salesforce
7
4
September 23, 2020
Anyone having issues with the Apex Relay Debugger in VS code today?

I saw that there were some changes related to unit test logic in latest release (https://github.com/forcedotcom/salesforcedx-vscode/pull/2961) and it seems like the SF team is already aware of the issues, (see comments here https://github.com/forcedotcom/salesforcedx-vscode/issues/2981) but I didn't see any issue like Yours created in Github issues. I'd suggest You to create one, this is the fastest way to get it fixed

More on reddit.com
🌐 r/SalesforceDeveloper
1
8
February 27, 2019
PSA: Apex of Filth in Act 3 can have a glitched layout
Spent around an hour trying to find the key, assumed I was missing something. The region wasn't connected lol More on reddit.com
🌐 r/PathOfExile2
16
6
June 1, 2024
With the coolest Apex map gone from rotation in only one season, here are some cool spots to get you ready for when it's back in.

How are you able to host custom matches with only 1 team?

More on reddit.com
🌐 r/Apexrollouts
26
200
September 1, 2023
🌐
Salesforce Developers
developer.salesforce.com › docs › atlas.en-us.apexcode.meta › apexcode › langCon_apex_collections_maps.htm
Maps | Apex Developer Guide | Salesforce Developers
A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.
🌐
Decodeforce
decodeforce.com › blogs › apex-map-class-methods-and-examples
Salesforce apex map class and methods with practice examples
A comprehensive guide on apex map methods and how to use them for various map manipulation in salesforce with practice examples.
🌐
Mytutorialrack
mytutorialrack.com › home › understanding map methods in apex: key concepts and best practices
Understanding Map Methods in Apex: Key Concepts and Best Practices
June 1, 2023 - It offers several methods to manipulate and retrieve data from the map. Map methods in Apex provide a wide range of functionality, including searching for values, checking for key existence, and merging maps together.
🌐
CRS Info Solutions
crsinfosolutions.com › home › what is a map class in salesforce apex? with examples
What is a Map class in Salesforce Apex? with examples
Salesforce Training
The keys in a Map must be unique and are used to access the corresponding values. Apex provides several methods to manipulate these entries, such as put(), get(), and remove(), offering developers powerful tools to manage data effectively within their applications. I have enrolled for Salesforce Admin and development online course at CRS info solutions. It’s really the best training i have ever taken and syllabus is highly professional
Rating: 5 ​
🌐
Salesforce Developers
developer.salesforce.com › docs › atlas.en-us.maps_developer_guide.meta › maps_developer_guide › maps_apex_overview.htm
Salesforce Maps Apex Methods | Salesforce Maps Apex Developer Guide | Salesforce Developers
Apex is a typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Salesforce Platform server, in conjunction with calls to the API. Use the sample code in this Apex method documentation as a starting point for your Salesforce Maps ...
🌐
S2 Labs
s2-labs.com › home › maps in apex
Maps In Apex | Salesforce Developer Tutorials
August 7, 2025 - Sets in APEX · Sets Initialization ... Operators(<,>,<=,>=) Share Blog · Link Copied to Clipboard! Maps in Apex are collections of key-value pairs....
Rating: 4.7 ​ - ​ 1.35K votes
Find elsewhere
🌐
Forceshark
forceshark.com › blog › key-concepts-and-usage-of-maps-in-salesforce-apex
Key concepts and usage of Maps in Salesforce Apex | Blog
You can add key-value pairs to the map using the put method: ... for (String name : myMap.keySet()) { Integer age = myMap.get(name); System.debug(name + ' is ' + age + ' years old.'); } Maps allow flexibility in data types for keys and values. You can use various data types based on your specific requirements. Internally, many programming languages, including Salesforce Apex, implement maps using hash tables.
🌐
Quora
quora.com › What-is-Map-Class-in-Apex-Salesforce
What is Map Class in Apex Salesforce? - Quora
Answer: Map is a collection of key-value pair in Apex. You can use it to store id of any record as a key and the record details as a value in the map. Example: map accMap = new map (); accMap holds the collection of Id and Sobject as key-value pair.
🌐
JanbaskTraining
janbasktraining.com › home › salesforce maps: features, benefits & methods
Salesforce Maps: Features, Benefits & Methods
December 29, 2022 - Map Class keys and values can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. Map keys of type String are case-sensitive. Map methods, including put, get, containsKey, and remove treat ...
🌐
Salesforcepoint
salesforcepoint.com › 2020 › 07 › salesforce-apex-map-map-methods-with.html
Salesforce Apex Map & Map methods with Examples | Salesforce Lightning Web Components, Aura Components, Apex Triggers, Apex REST API Integration
First of all Map is a key and value pair i.e each and every value is associates with key. Here key is unique, that means if we put one key,value pair into Map, we should not add same key one more time.
🌐
Reddit
reddit.com › r/salesforce › using maps in apex (beginner)
r/salesforce on Reddit: Using Maps in Apex (beginner)
September 23, 2020 -

I’ve been learning Apex for a little bit now and have a pretty novice understanding of how it all works, but the concept I’m struggling with the most is using maps instead of lists or sets.

Does anyone have good reference material or examples on when Map is useful/what’s really happening in the background? I feel like I’m really close to fully grasping it, but there’s still something missing where I’m not fully understanding the value.

I keep watching tutorials online and they’re definitely inching me closer to a revelation but I’ve failed to find one that really digs in.

Top answer
1 of 5
10
Sounds liek you don't have a grasp of what the differences are. These concepts are not unique to Apex. A list is an ordered sequence of items, like people waiting to get their number called. The thing is, one person can have more than one number assigned, so they can appear in the waiting list more than once. A set is almost like a list except it does not allow for a person to have more than one chance to be in the waiting list (so it only appears once on the whole waiting list) and it's not ordered, so doesn't matter what number the person got assigned to it. A map is a representation of the person waiting and it's number. That number is unique, so it's the key, the person assigned to the number is the value, so each entry of the map is a pair where you can't have two pairs with the same key. Where does it all make sense to use? Well, it depends on the use case. Let's say you want to check all the accounts of all the opportunities to get the account type, the account ID, the name and the opportunity Id and Opp name and export it to a csv so someone somewhere can analyze it. You do your SOQL query, get everything in a nice list and you output it into a nice excel sheet with a pretty header, mail it to the guy that requested it. You come up with this little piece of code: List lstOpp = [Select Id, AccountId, Account.Type from Opportunity]; String output = ''; for(Opportunity opp : lstOpp){ output+=opp.Id+','; output+=opp.AccountId+','; output+=opp.Account.Type+'\n'; } system.debug(output); A day later he replies: "hey! I'm noob at excel and there's duplicates here I don't know how to get rid of. Can you just send it to me without duplicates? Thanks!" You then think: Ok, I'll just add the Opportunities I get from the query and put it into a Set! That way, they get the information they want and no duplicates, right? Right!? Let's see... List lstopp = [Select Id, AccountId, Account.Type from Opportunity]; String output = ''; Set stOpp = new Set(); for(Opportunity opp : lstopp){ stOpp.add(opp); } for(Opportunity opp : stOpp){ output+=opp.Id+','; output+=opp.AccountId+','; output+=opp.Account.Type+'\n'; } system.debug(output); That't not right! My unique value is an opportunity... What I need is to have something that allows me to check if a certain Account is already added on the list I'm writting down on the CSV. Let's however see how this can be done by throwing a Map into the mix :) List lstopp = [Select Id, AccountId, Account.Type from Opportunity]; String output = ''; Map mapOppsByAccountId = new Map(); for(Opportunity opp : lstopp){ /* Notice what happens if you put the same key twice: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm#apex_methods_system_map */ mapOppsByAccountId.put(opp.AccountId,opp); } for(Id accountId : mapOppsByAccountId.keySet()){ Opportunity opp = mapOppsByAccountId.get(accountId); output+=opp.Id+','; output+=opp.AccountId+','; output+=opp.Account.Type+'\n'; } system.debug(output); Not the best example but I think it helps. If you have more questions (or if I made it even more complicated) let me know.
2 of 5
3
Maps allow you to locate data in a list very easily. Let's say you needed to find a record based on Id. If you just used a list, you would have to iterate through the list using an if statement to find the record with the id that matched your id. With a Map you can simple do a Get statement to return the record with the matching Id. Thinking them as a way to arrange data for easy retrieval later.
🌐
SFDC Kid
sfdckid.com › 2019 › 04 › salesforce-apex-collection-map.html
APEX COLLECTION: Map - SFDC Kid
Salesforce Apex Collection : Map Salesforce Apex Collection is a collection of key-value pairs where each unique key maps to a single value. salesforce Apex Collection in simple and easy steps starting from basic to advanced concepts with examples including salesforce Overview, salesforce Architecture, salesforce Environment, salesforce Sales, salesforce Service Cloud, salesforce Navigating Setup, salesforce Standard, salesforce Custom Objects, salesforce Master Detail Relationship, salesforce Lookup Relationship, salesforce Schema Builder, salesforce Control Access to the Organization, Contro
🌐
Code With Sally
codewithsally.com › home › blog archive › beginner’s guide to salesforce apex: an introduction to collections – lists, sets, and maps
Introduction to Collections : Lists, Maps & Sets in Salesforce Apex
March 20, 2024 - When it comes to iterating over a Map in Salesforce, it contains key-value pairs. There are two ways to loop through the values in a Map. One way is to iterate over the keys and then use the ‘get’ method to retrieve the value associated with each key.
🌐
ACTE
acte.in › home › exploring the map methods in salesforce: functions and use cases
Map Methods in Salesforce Apex Developer Guidelines | Updated 2025
CyberSecurity Framework and Implementation Article
Map Methods in Salesforce ⭐ Explore essential Map methods in Salesforce Apex, including put, get, containsKey, and more, to manage key-value data effectively One of best Institute to learn CyberSecurity Framework and Implementation from ACTE . Really impressive model where you can learn technical Skills , Soft Skill and get help to kick start your first Job as well.
Rating: 5 ​
🌐
CRS Info Solutions
crsinfosolutions.com › home › collections in apex: lists, sets, and maps
Collections in Apex: Lists, Sets, and Maps
Salesforce Training
Lists maintain order, Sets ensure uniqueness, and Maps allow for efficient data retrieval. Choosing the right type of collection depends on your specific needs in your Apex code. These collection types help you organize and manipulate data efficiently, making them valuable tools in Salesforce development. As you become more proficient in Apex, you’ll find yourself using collections frequently to handle complex data scenarios in your applications. You can explore all the String methods ... I have enrolled for Salesforce Admin and development online course at CRS info solutions. It’s really the
Rating: 5 ​
🌐
SaaS Guru
saasguru.co › salesforce-map-class
Salesforce Map Class: Comprehensive Guide
May 24, 2024 - The ‘size()’ method retrieves the total count of key-value pairs present within the Map. ... In this example, the count of key-value pairs within the Map is saved in the Integer variable named ‘mapSize’. These are just a few of the many useful Apex Map Methods available in the Salesforce Map Class and Apex Collections framework.
🌐
C# Corner
c-sharpcorner.com › article › apex-map-in-salesforce
Apex Map In SalesForce
September 19, 2019 - Log into your Salesforce account and click the "Developer Console". ... For learning more about Apex DataType, please refer to this link. Now, we can create a new Apex Class named ApexMap and the file named as ApexMap.apxc. After creating the Apex class ApexMap, add a Maptest method for creating and testing the map and its methods.
🌐
Intellipaat
intellipaat.com › home › blog › what are the map methods available in salesforce?
What are the Map Methods Available in Salesforce? - Intellipaat
April 3, 2025 - If a key already exists in a map and you attempt to add it again with a different value, the old value will take precedence over the new value. The term “map” on Salesforce refers to a collection of key-value pairs, so it can control data types like primitive data, Apex objects, and sObjects, among others. When it comes to wisely using Salesforce map methods...