Edit:

This is now a function you can use. It was implemented in the Spring 18 release.


I don't know of an official reason "why," but there's an idea you can vote on. I'll be sure to ask about it when I get a chance...

As I posted in that idea a few years ago, there's a quick one-liner you can use that's (relatively) faster than a straight loop, modified to be polymorphic:

Boolean listContains(Object[] source, Object target) {
    return (new Set<Object>(source)).contains(target);
}

Example uses in executeAnonymous:

Account a = new Account(Name='Test');
Account[] aList = new Account[] { a };
System.assert(listContains(aList, a));

Integer[] values = new Integer[] { 1, 1, 2, 3, 5 };
System.assert(listContains(values, 3));
System.assert(!listContains(values, 7));
Answer from sfdcfox on Stack Exchange
🌐
S2 Labs
s2-labs.com › home › lists in apex
Lists in Apex | Salesforce Developer Tutorials
August 6, 2025 - Lists in Apex are an ordered collection of elements used to store data in a sequence.
Rating: 4.7 ​ - ​ 874 votes
Discussions

apex - List.contains() method in Salesforce - Salesforce Stack Exchange
Is there any specific reason why salesforce did not provide list.contains() method. Edit 1: The below methods are added to List class and are available after Spring 18 release to Sandboxes and More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
apex - List class methods dynamically - Salesforce Stack Exchange
Is there a way to programmatically get a list of methods of a specified class? I know I can get the class body by querying ApexClass. However, this just gives a string that I should then parse. Pa... More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
apex method for counting
Seeing your code would make it easier but you can use .size() on any list to return the number of records. Google Apex List methods for more detail. More on reddit.com
🌐 r/SalesforceDeveloper
10
4
February 17, 2022
How to use an Apex-Defined Data Type to pass an HTTP response to a Flow?
Unfortunately, that resulted in a compilation error: InvocableMethod methods do not support return type of List So although I vaguely remembered InvocableMethods needing to return lists, I decided to try returning a simple TestYesNoinstead. No luck: InvocableMethod methods do not support return type of TestYesNo At first I thought the problem was that InvocableMethods can't return a List of a class defined inside Apex (so not an sObject) but it seems it's not the case according to this : A list of a user-defined type, containing variables of the supported types and with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation. Could this be the issue? I see your variables have the AuraEnabled annotation. Should it be changed to Invocable maybe? Sorry if I can't be more help, I haven't personally experienced this but tried to help as it seems interesting. Edit: Rodrigo over in the StackExchange post highlighted the same thing as me lol. I believe we are on the right track here, just missing katiekodes to try it out. More on reddit.com
🌐 r/salesforce
12
7
May 29, 2019
🌐
Decodeforce
decodeforce.com › blogs › apex-list-methods-and-examples
Salesforce apex list class and methods with practice examples
A comprehensive guide on apex list methods and how to use them for various list manipulation in salesforce with practice examples.
🌐
TutorialsPoint
tutorialspoint.com › apex › apex_collections.htm
Apex - Collections
Following are some most frequently used methods − ... // Initialize the List List<string> ListOfStatesMethod = new List<string>(); // This statement would give null as output in Debug logs System.debug('Value of List'+ ListOfStatesMethod); // Add element to the list using add method ...
🌐
Salesforce Developers
developer.salesforce.com › docs › atlas.en-us.apexcode.meta › apexcode › langCon_apex_collections_lists.htm
Lists | Apex Developer Guide | Salesforce Developers
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.
Find elsewhere
🌐
CRS Info Solutions
crsinfosolutions.com › home › list class in salesforce apex
List Class in Salesforce Apex
Salesforce Training
In Apex, the List class is a collection type that represents a dynamically-sized array. It is part of the Salesforce Apex Collection framework and provides methods to manipulate lists of objects 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 ​
🌐
SFDC Stop
sfdcstop.com › 2021 › 09 › list-data-structure-in-apex-apex-data.html
List Data Structure in Apex | Apex Data Structure Tutorials by SFDC Stop - SFDC Stop
September 10, 2021 - Each element in a list is associated with an index starting from 0, for example: the list above contains 5 elements which are stored in the memory as follows: Let's say you want to access element at index 3, you can simply refer to that by: numbers[3] or you can also use the get() method as: numbers.get(3).
🌐
Apex Trader Funding
support.apextraderfunding.com › hc › en-us
Apex Trader Funding
Help Center · Search our knowledge base or browse content below · Search · 💬 Need Help
🌐
S2 Labs
s2-labs.com › home › lists initialization in apex
Lists Initialization in APEX | Salesforce Developer Tutorials
August 6, 2025 - The syntax for initializing a list in Apex involves specifying the type of the list and creating a new instance of it. Here is the basic syntax: ... This is the most common method to initialize a list.
Rating: 4.6 ​ - ​ 675 votes
🌐
Code With Sally
codewithsally.com › home › blog archive › beginner’s guide to salesforce apex: an introduction to collections – lists, sets, and maps
Beginner’s Guide to Salesforce Apex: An Introduction to Collections - Lists, Sets, and Maps
March 20, 2024 - Each item in an Apex List has a unique Index, which can be thought of as its address. This makes it easy to retrieve a specific item from the List by using its Index as a reference point. In contrast to Sets, Lists maintain the order of elements and enable duplicates. The below syntax is used to declare and initialize an empty List, adding items using the “add” method and retrieving an item from the List using the “get” method:
🌐
Apex Hosting
apexminecrafthosting.com › pricing
Packages and Pricing - Apex Hosting
December 4, 2025 - See prices and special offers for our Minecraft hosting plans. All plans include DDoS protection, premium hardware and industry leading support.
🌐
MicroPyramid
micropyramid.com › blog › how-to-use-list-methods-in-salesforce
How to Use List Methods in Salesforce | MicroPyramid
If the list is of sObject records, the duplicate list can only be a copy of the list. Only the duplicate will have references to each object, but the sObject records themselves will not be duplicated. To duplicate these sObject records, we have to use deepClone method.
🌐
LinkedIn
linkedin.com › pulse › list-methods-apex-amit-khandelwal
List Methods in APEX
December 22, 2021 - Creates a new instance of the List class by copying the elements from the specified list.
🌐
CRS Info Solutions
crsinfosolutions.com › home › array methods in salesforce apex
Array methods in Salesforce Apex
Salesforce Training
On January 14, 2024, Posted by CRS Info Solutions , In Salesforce Apex Tutorial, With Comments Off on Array methods in Salesforce Apex · Salesforce Apex Tutorial – Chapter 7 – Apex Arrays ... How can you efficiently paginate a list of records in Apex for display in Visualforce or Lightning ... 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 ​
🌐
Nebula Consulting
nebulaconsulting.co.uk › home › insights › list processing in apex with map(), filter(), and more
List Processing in Apex with map(), filter(), and more
September 1, 2025 - These methods provide a nice abstraction for picking elements from an array with filter() , and for modifying the values with map() . The operations compose together nicely, so we can write neat code to process arrays which focuses on intention rather than having to write explicit for-loops. There are lots of things we do in Apex that are conceptually simple, but require chunks of boilerplate to achieve.
🌐
Medium
medium.com › creme-de-la-crm › apex-updates-new-list-tricks-7fc3afbd4223
Apex Updates: New List Tricks
April 9, 2019 - Lists also picked up their own index method, so devs can quickly determine where an element is in any given list. Simply add a indexOf(listElement) and it’ll return the position of the first occurrence of the specified list element (as an integer) and, if the list doesn’t contain the element, it’ll return a -1! ... So clean up your code and say goodbye to that spaghetti! You can see all of the Apex class updates from Spring ’18 right here and, if you still need a hand turning your vision into functioning code, give us a call!