A beginner's guide to using map methods in Salesforce

Liam Costello by Liam Costello on February 1, 2023  |  4 minute read

Salesforce has become a titan in the world of cloud computing and business data, consistently ranking as the number one customer relationship management (CRM) platform. In fact, the International Data Corporation (IDC) estimates that Salesforce CRM takes up 22.9% of the global market share.

However, while Salesforce is widely used, it isn't exactly the most user-friendly platform. For your Salesforce developer, this means analyzing and designing CRM workflows and custom solutions can be a challenging and time-consuming process.

One particular element that can be perplexing is the Salesforce Map methods. To find out what these are, why they're important, and how to use them, let's start by discussing Salesforce maps.

What is a Salesforce Map?

In the context of Salesforce development, a map is a data structure that stores key value pairs. What are map keys and values? These can be any kind of data, including a(n):

  • Object
  • Salesforce collection
  • Primitive data type
  • User defined type
  • Built-in Apex type

You can think of a Salesforce map as a dictionary in which each key corresponds to a specific value. For example, the table below would be a simple map of the words and definitions we’ve covered so far:

Word (Key) Salesforce map Key value pair
Definition (Value)

A collection of key value pairs where each unique key maps to a single value.

A representation of any data type with two related elements.

Here, you can see that each unique key, or word in this instance, matches up with a specific value in the matrix.

What is a Salesforce Map method?

Salesforce map methods are functions that allow you to manipulate map data tables in a variety of ways, such as:

  • Adding and removing key value pairs
  • Sorting the Salesforce map by data type
  • Searching for a specific key or value
  • And much more

All map methods are also instance methods, operating on a single instance of a map. That means, before you can call a map, you need to create an object of the same class. By changing your maps using these methods, you can quickly find the information you’re looking for with a single key.

So, what are the different kinds of map methods?

The different map methods in Salesforce

Salesforce offers a plethora of map methods to help you manage the information in your data tables. Here are all 17 map methods you can use in Salesforce and what they do:

Method Description
clear() Removes all of the key-value mappings
clone() Makes a duplicate copy of the entire map
containsKey(key) Returns "true" if there is a mapping for the specified key
deepClone() Makes a duplicate of a map, including sObject records if it has the same values
equals(map2) Compares your current map with the specified map and returns “true” if both maps are equal
get(key) Returns the value mapped to the specified key, or “null” if there is no value for the key
getSObjectType() Returns the token of the sObject type that makes up the map values
hashCode() Returns the hash code corresponding to the map
isEmpty() Returns true if the map doesn’t have any key value pairs
keySet() Returns a set that contains all of the map keys it contains
put(key, value) Adds a new key value pair to the map, associating the specific value with the unique key
putAll(fromMap) Copies all of the mappings from a specified map to the original map
putAll(sobjectArray) Adds a list of sObject records to a map declared as Map<ID, sObject>, or Map<String, sObject>
remove(key) Removes all the mapping for a specified key and returns the corresponding value
size() Returns the total number of key value pairs in the map
toString() Returns the string representation of the map
values() Returns a list containing all the values in the map

Visualize your Salesforce data with eSpatial

eSpatial is a powerful Salesforce integration that centralizes all of your data on a single platform for mapping, territory planning, and route optimization.

With eSpatial, you can:

  • Visualize data about your leads, customers, and sales performance with advanced styling options.
  • Align, balance, and optimize your territories to prioritize high-value accounts while maintaining an equitable distribution of opportunities for your reps.
  • Plan routes weeks in advance and optimize them while your sales team is on the road to maximize productivity and performance.

As an alternative to Salesforce Maps, eSpatial is a location intelligence solution that’s easy to use and offers advanced functionality. Simply upload data from your Salesforce CRM, ERP, POS, or any other source — as long as it’s in an Excel or CSV format. From there, our algorithms automatically bring your data to life through vibrant sales maps that deliver actionable insights into your business.



Get started with eSpatial today

Liam Costello Written by

Liam Costello

Liam is an eSpatial account manager and mapping expert. He specializes in helping businesses solve problems and increase sales through mapping visualization, territory management, route optimization and more. Liam holds a Master's Degree in Geographical Information Systems (GIS) and Remote Sensing.

Read more from Liam Costello