
A Set in Salesforce is an unordered collection of elements that contain any type of data types like primitive types, collections, sObjects, user-defined types, and built-in Apex types. 2. Apex List An Aapex List is a collection of ordered elements that can be located based on an index. This order follows a definite pattern.
Full Answer
How do I create a set in Salesforce?
To declare a set, use the Set keyword followed by the primitive data type name within <> characters. For example: The following example shows how to create a set with two hardcoded string values. To access elements in a set, use the system methods provided by Apex. For example:
What is the difference between list and set in Salesforce?
A List is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. Whereas, Set is an unordered collection of elements that do not contain any duplicates.
What is permission set in Salesforce?
Permission Sets A permission set is a collection of settings and permissions that give users access to various tools and functions. Permission sets extend users’ functional access without changing their profiles. Available in: Salesforce Classic (not available in all orgs) and Lightning Experience
What is Salesforce and how does it work?
As we all know, Salesforce is a cloud-based online customer relationship management (CRM) software solution. SalesForce helps marketing, sales, commerce, and service and IT teams to work at a single integrated CRM platform.

How do I create a Set in Salesforce?
How to use Set in SalesforceSyntax:Creating a set: Set
What is Set in Salesforce?
A Set in Salesforce is an unordered collection of elements that contain any type of data type like primitive types, collections, sObjects, user-defined types, and built-in Apex types. Set methods in Salesforce do not allow duplication. The insertion order is not preserved in the Set.
What are the methods of Set in Salesforce?
There are several kinds of methods available in the set class. So, here are the list methods in Salesforce.add(set Element)addAll(SetElement)clear()clone()add(index, setElement)equals(set2)removeAll(setOfElementsToRemove)remove(setElement)More items...•
Why we use Set in Salesforce?
Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements. So, use set if you want to make sure that your collection should not contain Duplicates.
What is use Set?
The purpose of using sets is to represent the collection of relevant objects in a group. In maths, we usually represent a group of numbers like a group of natural numbers, collection of rational numbers, etc.
What is Set ID in Salesforce?
In apex, the Id is a primitive data type that maintains the data integrity of the data type by only allowing only Ids(or Strings with Id patterns). If you would like to test it out, put the following into anonymous apex and execute: Id errorId = '001aaaaaaaaaaaa';
Can we use Set in SOQL query?
No issues at all. Yes we can.
How do I convert a list to a Set in Salesforce?
Converting from a List to Set, can be done using the set's constructor. List
How do I start Set in Apex?
To declare a set, use the Set keyword followed by the primitive data type name within <> characters. For example: Set
What is Set and map in Salesforce?
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. A set is an unordered collection of elements that do not contain any duplicates.
What is list Set and map?
List in Java provides ordered and indexed collection which may contain duplicates. The Set interface provides an unordered collection of unique objects, i.e. Set doesn't allow duplicates, while Map provides a data structure based on key-value pair and hashing.
Why Set is unordered in Salesforce?
A sorted/unordered collection means that not only does the collection have order, but the order depends on the value of the element. A SortedSet is an example. In contrast, a collection without any order can maintain the elements in any order. A Set is an example.
What is a set in a collection?
Until now, you’ve created one type of collection, a list. A set is an unordered set of unique items of the same type. Similar to a list, a set is a group of items, called elements, and all elements have the same data type, such as string, integer, or even Account.
What is an Apex list?
As you already learned, a list is an ordered collection of items with the same data type. Each item has a position called an index. This makes it easy to retrieve items in the list by the numbered index. But Apex collections are more than just lists. The other two types of collections are sets and maps.
Why can't a set have duplicates?
Because the elements are unordered , a set can't have any duplicates. If you try to add an element that’s already in the set, you don’t get an error, but the new value is not added to the set. Remember that when you loop through a list, you always access its items in the order that the items were added to the list.
addAll (fromList)
Adds all of the elements in the specified list to the set if they are not already present.
addAll (fromSet)
Adds all of the elements in the specified set to the set that calls the method if they are not already present.
containsAll (listToCompare)
Returns true if the set contains all of the elements in the specified list. The list must be of the same type as the set that calls the method.
containsAll (setToCompare)
Returns true if the set contains all of the elements in the specified set. The specified set must be of the same type as the original set that calls the method.
equals (set2)
Compares this set with the specified set and returns true if both sets are equal; otherwise, returns false.
removeAll (listOfElementsToRemove)
Removes the elements in the specified list from the set if they are present.
removeAll (setOfElementsToRemove)
Removes the elements in the specified set from the original set if they are present.
What is permission set in Salesforce?
A permission set is a collection of settings and permissions that give users access to various tools and functions. Permission sets extend users’ functional access without changing their profiles. Users can have only one profile but, depending on the Salesforce edition, they can have multiple permission sets.
Can you create a permission set based on tasks?
You can create a permission set based on the tasks that these users must perform and include the permission set within permission set groups based on job functions. If a permission isn’t enabled in a profile but is enabled in a permission set, users with that profile and permission set have the permission.
Can you have multiple Salesforce profiles?
Users can have only one profile but, depending on the Salesforce edition, they can have multiple permission sets. You can assign permission sets to various types of users, regardless of their profiles. Create permission sets to grant access among logical groupings of users, regardless of their primary job function.
What is a profile in Salesforce?
A profile is a group/collection of settings and permissions that define what a user can do in salesforce. A profile controls "Object permissions..... A profile is a group/collection of settings and permissions that define what a user can do in salesforce.
Can you define profiles in Salesforce?
You can define profiles by user’s job function. For example System Administrator, Developer, Sales Representative. A profile can be assigned to many users, but a user can be assigned a single profile at a time. Types of profiles in Salesforce. Standard profiles: By default, salesforce provides below standard profiles.

Learning Objectives
Follow Along with Trail Together
- Want to follow along with an expert as you work through this step? Take a look at this video, part of the Trail Together series on Trailhead Live. (This clip starts at the 49:06 minute mark, in case you want to rewind and watch the beginning of the step again.)
Introduction
- As you already learned, a list is an ordered collection of items with the same data type. Each item has a position called an index. This makes it easy to retrieve items in the list by the numbered index. But Apex collections are more than just lists. The other two types of collections are sets and maps.
Sets
- Until now, you’ve created one type of collection, a list. A set is an unordered set of unique items of the same type. Similar to a list, a set is a group of items, called elements, and all elements have the same data type, such as string, integer, or even Account. Unlike a list, a set maintains no particular order for its elements. Because the elem...
Set Methods
- Each type of collection has its own methods. You added Black, White, and Herbal to a list of tea types with the commonly used addmethod. To learn more about set methods, see the Resources at the end of this unit. Add a Duplicate Value to a Set 1. In the Tea class, replace the orderTea method (lines 2–8) with this code:public static void orderTea(){ Set<String> teaTypes = new Set …
Maps
- A map is a more complex collection than either a list or a set. Each item in a map has two parts: a key and a value, known as a key-value pair. Keys and values can be any data type. Although each key is unique, values can be repeated within a map. Imagine a map of telephone country codes. The country code is the key and the name of the country is the value. Each country code is uniqu…
Resources
- Apex Developer Guide: Apex Set Methods
- Apex Developer Guide: Maps
- Apex Developer Guide: Apex Map Methods