FOMO ALERT : FLAT 10% OFF * on ANY COURSE & 25% OFF on TWO COURSES FLAT10

- Salesforce Blogs -

How Important is to Know About the Map in Salesforce in 2022?

What exactly is a map in Salesforce?

In the world of CRM platforms, Salesforce leads the chart. Spending in CRM will be around US$ 670 billion in 2022. Salesforce forms 19.5% of the global CRM market share. Now, when you start learning about Salesforce, you will come across the term Salesforce Map Class. But you must have wondered what it is exactly, right? 

Well, no worries! 

We are here with a complete guide on Salesforce Map Class which you should not miss!

So why wait? Let’s scroll down till the end into a holistic learning experience about map methods in Salesforce.

Salesforce Map Class - What Is a Map in Salesforce?

The Salesforce Map Class is a collection of Map methods in Salesforce. These are all instance methods, that is, they operate on a particular instance of a map.

The following are the instance methods for maps:

Salesforce Map Class Features

Read: Salesforce Certifications are in Demand --- Make Sure You Have One!
  • A map is a collection of key-value pairs where each unique key maps to a single value. Map keys can be any primitive data type like string, integer,decimal, Id while values can be a primitive, sObject, collection type or an Apex object.
  • 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 these keys as distinct.
  • The Salesforce Map gives value on the basis of the key.
  • Key is always unique but a value can be duplicated. 

What is the benefit of Salesforce Map Class? 

Well, Map Class is a simple approach to write an Apex Class or trigger in bulk.

Find out the detailed syntaxes about Map methods in Salesforce to write Apex Class or trigger below!

Salesforce Map Class Constructors

The following are constructors for Map.

  • Map<T1,T2>() - In the Map Class, this constructor creates a new instance of the Salesforce Map. T1 is the data type of the keys and T2 is the data type of the values.
  • Map<T1,T2>(mapToCopy) - This constructor generates a new instance of the Salesforce Apex Map Class. It initializes it just by copying the specified map entries. T2 is the data type of the values and T1 is known as the data type of the values.
  • Map<ID,sObject>(recordList) - This Map Class constructor generates a new instance of the Map Apex class. Also, this constructor populates it with the sObject records’ passed-in list. The Map keys get populated with the IDs of sObject. Wherein, the values are known as sObjects.

Syntax


Map<integer, string>exMap= new map<integer, string>();
exMap.put(1,'James');
exMap.put(2,'Daniel');
exMap.put(3,'Peter');
string name= exMap.get(1);
string name1= exMap.get(2);
string name2= exMap.get(3);
system.debug(name);//James
system.debug(name1);//Daniel
system.debug(name2);// Peter
set<integer>key= exmap.keyset();
list<string>values=exmap.values();
system.debug(values);//James, Daniel, Peter

Once you’re familiar with the syntax and the fundamentals of Salesforce, mapping with it becomes simpler. Learn more with our Self-learning module.

Learn Salesforce in the Easiest Way

  • Learn from the videos
  • Learn anytime anywhere
  • Pocket-friendly mode of learning
  • Complimentary eBook available

Read: What Is Interesting About Salesforce Internships?

Map Class Methods

The following are methods for Map. All are instance methods.

  • clear() Removes all of the key-value mappings from the map.
  • clone() Makes a duplicate copy of the map.
  • containsKey(key) This method returns true if the map contains - the  If the key is a string, the key value is case-sensitive.
  • deepClone() DeepClone () method creates a duplicate copy of a map, including sObject records if the map has sObject record values .
  • equals(map2) It compares a map with a specified map and returns true if both maps are equal; otherwise, returns false.
  • get(key) This method returns the value of the specified key which is mapped, or it returns null if the map contains no value for this key.
  • getSObjectType() This method returns the value of the sObject type in format of key and value.
  • isEmpty() If the map has zero key-value pairs it returns true.
  • keySet() Returns a set that contains all of the keys in the map.
  • put(key, value):
  • Associates the specified value with the specified key in the map.
  • putAll(fromMap) Copies all of the mappings from the specified map to the original map.
  • putAll(sobjectArray) Adds the list of sObject records to a map declared as Map<ID, sObject> or Map<String, sObject>.
  • remove(key) This method removes the mapping for the specified key from the map, if present, and returns the corresponding value.
  • size() Returns the number of key-value pairs in the map.
  • values() This method returns a list which contains all the values in the map.The values are returned in an arbitrary order.

get(key):


list<account>myAccounts = new list<account>();
myAccounts = [Select ID, Name from Account limit 10]; 
map<id,string>myAMap = new map<id,string>();
for ( Account a : myAccounts ){
//Here putting account Id and name to map
myAMap.put(a.ID, a.Name);
    } 
for ( ID aID : myAMap.keySet() ){
system.debug(loggingLevel.debug, myAMap.get(aID));
    }    

Maps Class and Objects of Apex Salesforce

putAll(fromMap):


Map<String, String> map1 = new Map<String, String>();
map1.put('Red','LightRed');
Map<String, String> map2 = new Map<String, String>();
map2.put('Blue','DarkRed');
// Add map1 entries to map2
map2.putAll(map1);
System.debug(map2.values());//(LightRed, 'DarkRed')


remove(key):


Map<String, String>colorCodes =   new Map<String, String>();
colorCodes.put('Red', 'FF0000');
colorCodes.put('Blue', '0000A0');
colorCodes.put('Green', '0000A0');
System.debug('printing=== '+colorCodes);// Blue=0000A0, Green=0000A0, Red=FF0000
for(String key:colorCodes.keySet().clone()) {
colorCodes.remove('Green');
system.debug(colorCodes);// Blue=0000A0, Red=FF0000
}


Salesforce Training For Administrators & Developers

  • Personalized Free Consultation
  • Access to Our Learning Management System
  • Access to Our Course Curriculum
  • Be a Part of Our Free Demo Class

Values ():


Map<String, String>colorCodes = new Map<String, String>();
colorCodes.put('FF0000', 'Red');
colorCodes.put('0000A0', 'Blue');
List<String> colors = new List<String>();
colors = colorCodes.values();
system.debug(colors);//(Red, Blue)

getSObjectType()


Map <id,Account>acctMap = new map<id,account>([select  name from  Account limit 10]);
for(string accValue:acctmap.keyset()){
system.debug(acctmap.get(accValue));
}

Maps Class and Objects of Apex Salesforce

Example How to display records on the basis of alphabet? 


Apex class
public class DynamicSearchExample {
public Map<string,list<account>>accountsMap {get; set;}
public List<selectoption> keys {get; set;}
public String selectedKey {get; set;}
public Map<string, account>accsByName {get; set;}
public Set<string>getMapKeys(){
returnaccountsMap.keySet();
    }
publicDynamicSearchExample(){
accsByName=new Map<string, account>();
        List<string>sortedKeys=new List<string>();
accountsMap=new Map<string, list<account>>();
accountsMap.put('All', new List<account>());
        List<account>accs=[select Name, industry,type,phone from Account order by Name asc];               
for (Account acc : accs){
accountsMap.get('All').add(acc);
            String start=acc.Name.substring(0,1);
            List<account>accsFromMap=accountsMap.get(start);
if (null==accsFromMap){
accsFromMap=new List<account>();
accountsMap.put(start,accsFromMap);
            }
accsFromMap.add(acc);
accsByName.put(acc.name,acc);
        }
keys=new List<selectoption>();
for (String key : accountsMap.keySet()){
if(key != 'All'){
sortedKeys.add(key);
            }
        }
sortedKeys.sort();
sortedKeys.add('All');
for (String key : sortedKeys){
keys.add(new SelectOption(key, key));
        }
selectedKey='All';
    }
}
Visualforce page
<apex:page controller="DynamicSearchExample">
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0Afunctionredraw_accounts()%7B%0A%0A%20%20%20%20%7D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />
<apex:form>
<apex:actionFunction name="redraw_accounts" rerender="accs" status="status"/>
<apex:pageBlock title="Criteria">
<apex:outputLabel value="Starting Letter"/>
<apex:selectList value="{!selectedKey}" size="1" onchange="redraw_accounts()">
<apex:selectOptions value="{!keys}" />
</apex:selectList>
</apex:pageBlock>
<apex:pageBlock title="Accounts">
<apex:actionstatus id="status" startText="Loading Data..........." stopText="Loading completed....." >
<apex:facet name="start"/>
<apex:facet name="stop">
<apex:outputPanel id="accs">
<apex:pageBlockTable value="{!accountsMap[selectedKey]}" var="acc">
<apex:column value="{!acc.name}"/>
<apex:column value="{!acc.industry}"/>
<apex:column value="{!acc.type}"/>
<apex:column value="{!acc.phone}"/>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:pageBlock>
</apex:form>
</apex:page>

Output Maps Class and Objects of Apex Salesforce

Read: Top 10 Salesforce Automation Tools: Which Do You Use


That’s it for now!

Are you interested to learn more about Salesforce and exploring various career opportunities? Get a free but comprehensive guide at Salesforce Careers - Step By Step Salesforce Career Path

Finally on Salesforce Map Class

The Salesforce Map Class is essential to use in Salesforce as it makes it easy for writing the bulk apex class or trigger. Learning about the various elements of Map Apex Class is advantageous for Salesforce users and professionals. Becoming a PRO in Salesforce can help software developers earn a whopping US$ 110,000 on average.

However, as a beginner of Salesforce, you are unaware of various techniques that you can employ in script statements. In that case, learn all the skills necessary to be MASTER in Salesforce with JanBask Online Salesforce Training.

You can also get a free consultation on the Salesforce career by connecting with us at JanBask Training

Till then sign up with our newsletter to get more insightful guides on Salesforce. Do comment if our tips are helpful. 

Happy Learning! 

Read: Salesforce Certifications Paths- What does the Future hold for Salesforce?


FaceBook Twitter Google+ LinkedIn Pinterest Email

    Janbask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


Comments

  • K

    Kyle Lee

    Hi! This blog on Map Class is very informative. Can we have some more information on the Salesforce career path ?

     Reply
    • JanbaskTraining

      Hey, we thank you for your comment and interest. For further information, you can connect to us at https://www.janbasktraining.com/contact-us

  • M

    markyjones

    I am planning to go for a Salesforce Developer certificate, and this tutorial on Salesforce Map Class is a testimony of the fact that how in-depth you guys are with the technology. I Would like to get more information on the Salesforce Developer certificate.

     Reply
    • JanbaskTraining

      Hey, thanks a ton for your comment. We feel both countries are equally good from job perspectives. However, do connect with our experts at https://www.janbasktraining.com/contact-us

  • R

    Rafael Lewis

    Earlier I was confused about Salesforce Map and its use. But this blog is like a complete tutorial. However, I would like to know in-depth about all these certifications and which one will be more effective for me.

     Reply
    • JanbaskTraining

      Hey thank you so much. We are grateful that our blog has been a help to you! We can get your query resolved if you can just call our experts at https://www.janbasktraining.com/contact-us

  • J

    Jorge Hall

    Hey, the section about the Salesforce Map Constructors and the Syntaxes really helps! Need more details about each certifications.

     Reply
    • JanbaskTraining

      Thanks a ton that you liked our post. We request you to check our Salesforce Certification blog or connect with us to know more such enlightening information about Salesforce at https://www.janbasktraining.com/contact-us

  • E

    Emerson King

    Hi, the blog is very insightful. However, I am looking for more information specific to Salesforce Marketing Cloud Developer certification.

     Reply
    • JanbaskTraining

      Thank you for showing interest in us. We will request you to reach out to our education experts at https://www.janbasktraining.com/contact-us

  • A

    Arlo Hill

    Very informative blog. Please share more such information like this on various other topics as I am a tech geek and love learning various technologies!

     Reply
    • JanbaskTraining

      Thank you for showing interest in us. We really appreciate your zeal to learn. Will request you to reach out to our education experts at

  • E

    Erick Nelson

    Is SAP or Salesforce better with regards to job prospects?

     Reply
    • JanbaskTraining

      Thank you for showing interest in us! Well, both are good job-wise. However, Salesforce is the most used CRM in the world. So, opportunities in Salesforce may be higher in the days to come. Will request you to reach out to our education experts at https://www.janbasktraining.com/contact-us

  • C

    Cash Perez

    How to become a Salesforce Administrator? Can you share a guide on that?

     Reply
    • JanbaskTraining

      Surely we can! Go through our Salesforce Certification blog or reach out to our education experts at https://www.janbasktraining.com/contact-us

  • M

    Martin Roberts

    Is there any certification for the Salesforce Pardot area?

     Reply
    • JanbaskTraining

      Thanks for showing interest! Kindly reach out to our education experts at https://www.janbasktraining.com/contact-us

  • D

    Dallas Phillips

    The blog on Salesforce Map Class is extremely well-researched and nicely curated. Can we have more such insightful blogs on Salesforce going forward?

     Reply
    • JanbaskTraining

      Thanks for showing interest! You can check the Salesforce Blog page for more such information. Kindly reach out to our education experts at https://www.janbasktraining.com/contact-us

Trending Courses

AWS

  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

5 days 27 May 2022

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

12 days 03 Jun 2022

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

5 days 27 May 2022

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

5 days 27 May 2022

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

5 days 27 May 2022

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

5 days 27 May 2022

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

5 days 27 May 2022

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

12 days 03 Jun 2022

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation

Upcoming Class

20 days 11 Jun 2022

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks

Upcoming Class

13 days 04 Jun 2022

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning

Upcoming Class

26 days 17 Jun 2022

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop

Upcoming Class

5 days 27 May 2022

Search Posts

Reset

Receive Latest Materials and Offers on Salesforce Course

Interviews