The document describes common methods used for maps, lists, sets, strings, and sObjects in Apex. For maps, it outlines methods for adding, retrieving, and removing key-value pairs, checking for keys/values, and getting collections of keys/values. For lists and sets, it describes methods for adding/removing elements, retrieving elements, and checking for contents. For strings, it details methods for extracting characters/substrings, comparing strings, and manipulating string values. For sObjects, it lists methods for accessing, modifying, and saving field values, and getting metadata.
The document describes common methods used for maps, lists, sets, strings, and sObjects in Apex. For maps, it outlines methods for adding, retrieving, and removing key-value pairs, checking for keys/values, and getting collections of keys/values. For lists and sets, it describes methods for adding/removing elements, retrieving elements, and checking for contents. For strings, it details methods for extracting characters/substrings, comparing strings, and manipulating string values. For sObjects, it lists methods for accessing, modifying, and saving field values, and getting metadata.
The document describes common methods used for maps, lists, sets, strings, and sObjects in Apex. For maps, it outlines methods for adding, retrieving, and removing key-value pairs, checking for keys/values, and getting collections of keys/values. For lists and sets, it describes methods for adding/removing elements, retrieving elements, and checking for contents. For strings, it details methods for extracting characters/substrings, comparing strings, and manipulating string values. For sObjects, it lists methods for accessing, modifying, and saving field values, and getting metadata.
put(key, value) - This method adds a key-value pair to
the map. If the key already exists in the map, the value is overwritten.
get(key) - This method returns the value associated with
the specified key. If the key is not found in the map, null is returned.
containsKey(key) - This method returns true if the map
contains the specified key, otherwise it returns false.
containsValue(value) - This method returns true if the
map contains the specified value, otherwise it returns false.
isEmpty() - This method returns true if the map is
empty, otherwise it returns false.
size() - This method returns the number of key-value
pairs in the map.
keySet() - This method returns a set of all the keys in
the map.
values() - This method returns a list of all the values in
the map.
remove(key) - This method removes the key-value pair
with the specified key from the map. If the key is not found in the map, no action is taken.
clear() - This method removes all key-value pairs from
the map.
putAll(mapToCopy) - This method copies all the key-
value pairs from the specified map into the current map. Some more advanced methods:
entrySet() - This method returns a set of all the key-
value pairs in the map, as a Map.Entry object. The Map.Entry object contains both the key and value for each entry in the map.
getOrDefault(key, defaultValue) - This method returns
the value associated with the specified key, or the specified default value if the key is not found in the map.
putIfAbsent(key, value) - This method adds a key-value
pair to the map only if the key does not already exist in the map. If the key is already present, the existing value is returned and no action is taken.
replace(key, newValue) - This method replaces the
value associated with the specified key with the new value. If the key is not found in the map, no action is taken.
replaceAll(function) - This method replaces all the
values in the map with the result of applying the specified function to each value.
computeIfAbsent(key, function) - This method
computes the value for the specified key using the specified function if the key is not already in the map, and adds the key-value pair to the map.
computeIfPresent(key, function) - This method
computes a new value for the specified key using the specified function only if the key is already in the map, and updates the map with the new key-value pair.
compute(key, function) - This method computes a new
value for the specified key using the specified function, and updates the map with the new key-value pair. If the key is not already in the map, no action is taken. merge(key, value, function) - This method adds the key- value pair to the map if the key does not already exist, or updates the existing value with the specified function.
keySetForValues(values) - This method returns a set of
all the keys in the map that have the specified values.
LIST METHODS
add(element) - This method adds an element to the end
of the list.
addAll(list) - This method adds all the elements from
another list to the end of the current list.
clear() - This method removes all elements from the list.
contains(element) - This method returns true if the list
contains the specified element, otherwise it returns false.
get(index) - This method returns the element at the
specified index in the list.
indexOf(element) - This method returns the index of the
first occurrence of the specified element in the list, or -1 if the element is not found.
isEmpty() - This method returns true if the list is empty,
otherwise it returns false.
lastIndexOf(element) - This method returns the index of
the last occurrence of the specified element in the list, or -1 if the element is not found.
remove(index) - This method removes the element at
the specified index from the list. remove(element) - This method removes the first occurrence of the specified element from the list.
removeAll(list) - This method removes all the elements
in the current list that are also in the specified list.
retainAll(list) - This method removes all the elements in
the current list that are not in the specified list.
set(index, element) - This method replaces the element
at the specified index in the list with the specified element.
size() - This method returns the number of elements in
the list.
sort() - This method sorts the elements in the list in
ascending order, based on their natural ordering.
subList(fromIndex, toIndex) - This method returns a
new list containing the elements from the specified starting index to the ending index (exclusive).
SET METHODS
add(element) - This method adds an element to the set.
addAll(set) - This method adds all the elements from
another set to the current set.
clear() - This method removes all elements from the set.
contains(element) - This method returns true if the set
contains the specified element, otherwise it returns false.
isEmpty() - This method returns true if the set is empty,
otherwise it returns false. remove(element) - This method removes the specified element from the set.
removeAll(set) - This method removes all the elements
in the current set that are also in the specified set.
retainAll(set) - This method removes all the elements in
the current set that are not in the specified set.
size() - This method returns the number of elements in
the set.
toArray() - This method returns an array containing all
the elements in the set.
containsAll(set) - This method returns true if the set
contains all the elements in the specified set, otherwise it returns false.
equals(set) - This method returns true if the specified
set is equal to the current set, i.e., they have the same elements, otherwise it returns false.
hashCode() - This method returns a hash code value for
the set.
String Methods
charAt(index) - This method returns the character at
the specified index in the string.
compareTo(otherString) - This method compares the
current string to another string lexicographically. It returns 0 if the strings are equal, a negative number if the current string is less than the other string, and a positive number if the current string is greater than the other string. concat(otherString) - This method concatenates the current string with another string.
contains(substring) - This method returns true if the
current string contains the specified substring, otherwise it returns false.
endsWith(suffix) - This method returns true if the
current string ends with the specified suffix, otherwise it returns false.
equals(otherObject) - This method compares the
current string to another object. It returns true if the object is a string and contains the same characters as the current string, otherwise it returns false.
equalsIgnoreCase(otherString) - This method compares
the current string to another string, ignoring case differences. It returns true if the strings are equal, otherwise it returns false.
indexOf(substring) - This method returns the index of
the first occurrence of the specified substring in the current string, or -1 if the substring is not found.
isEmpty() - This method returns true if the current
string is empty, otherwise it returns false.
lastIndexOf(substring) - This method returns the index
of the last occurrence of the specified substring in the current string, or -1 if the substring is not found.
length() - This method returns the length of the current
string.
replace(oldValue, newValue) - This method replaces all
occurrences of the specified old value in the current string with the specified new value. startsWith(prefix) - This method returns true if the current string starts with the specified prefix, otherwise it returns false.
substring(startIndex) - This method returns a substring
of the current string starting at the specified index.
substring(startIndex, endIndex) - This method returns
a substring of the current string starting at the specified start index and ending at the specified end index.
toLowerCase() - This method returns a new string with
all the characters in the current string converted to lowercase.
toUpperCase() - This method returns a new string with
all the characters in the current string converted to uppercase.
trim() - This method returns a new string with all
leading and trailing whitespace characters removed.
sObjects Methods
get(fieldName) - This method returns the value of a
field on the sObject.
put(fieldName, fieldValue) - This method sets the value
of a field on the sObject.
getId() - This method returns the ID of the sObject.
getSObjectType() - This method returns the sObject
type of the sObject.
clone(shouldPreserveId) - This method creates a clone
of the sObject. The shouldPreserveId parameter determines whether the ID of the sObject should be preserved in the clone.
delete() - This method deletes the sObject from the
database.
getErrors() - This method returns a list of errors that
occurred when the sObject was last saved.
getFields() - This method returns a map of field names
to field values on the sObject.
getDescribe() - This method returns the describe result
for the sObject.
isSet(fieldName) - This method returns true if the
specified field on the sObject has been set, otherwise it returns false.
putAll(fieldValues) - This method sets multiple field
values on the sObject at once. The fieldValues parameter is a map of field names to field values.
putSObject(fieldName, fieldValue) - This method sets
the value of a field on the sObject to another sObject.
set(fieldName, fieldValue) - This method sets the value
of a field on the sObject. This method can also be used to set values on child sObjects.
toDebugString() - This method returns a string
representation of the sObject for debugging purposes.
undelete() - This method undeletes the sObject from the