Skip to content

UTIL_SObjectDescribe.FieldsMap ​

Class · Group: Utilities

Learn it: Utilities guide

apex
global inherited sharing class UTIL_SObjectDescribe.FieldsMap extends UTIL_SObjectDescribe.NamespacedAttributeMap

A subclass of NamespacedAttributeMap for handling field maps returned by DescribeSObjectResult.fields.getMap().


Methods ​

MethodDescription
global override Boolean containsKey(String name)Checks if the map contains a key with namespace handling enabled by default.
global override Boolean containsKey(String name, Boolean implyNamespace)Checks if the map contains a key with optional namespace handling.
global SObjectField get(String name)Retrieves an SObjectField by name with namespace handling enabled by default.
global SObjectField get(String name, Boolean implyNamespace)Retrieves an SObjectField by name with optional namespace handling.
global override Set<String> keySet()Returns the key set of the map with namespace handling disabled by default.
global override Set<String> keySet(Boolean implyNamespace)Returns the key set of the map with optional namespace handling.
global override Integer size()Returns the number of entries in the map.
global List<SObjectField> values()Returns a token for every field on the object, whatever its namespace.

containsKey ​

apex
global override Boolean containsKey(String name)

Checks if the map contains a key with namespace handling enabled by default.

Parameters

ParameterTypeDescription
nameStringThe key to check.

Returns Boolean — true if the key exists, false otherwise.

Example

apex
Boolean result = instance.containsKey('myName');
apex
global override Boolean containsKey(String name, Boolean implyNamespace)

Checks if the map contains a key with optional namespace handling.

Parameters

ParameterTypeDescription
nameStringThe key to check.
implyNamespaceBooleanWhether to handle namespace prefixes.

Returns Boolean — true if the key exists, false otherwise.

Example

apex
Boolean result = instance.containsKey('myName', true);

get ​

apex
global SObjectField get(String name)

Retrieves an SObjectField by name with namespace handling enabled by default.

Parameters

ParameterTypeDescription
nameStringThe API name of the field.

Returns SObjectField — The SObjectField, or null if not found.

Example

apex
UTIL_SObjectDescribe describe = UTIL_SObjectDescribe.getDescribe('Contact');
SObjectField field = describe.getFields().get('Email');
// field is Contact.Email
apex
global SObjectField get(String name, Boolean implyNamespace)

Retrieves an SObjectField by name with optional namespace handling.

Parameters

ParameterTypeDescription
nameStringThe API name of the field.
implyNamespaceBooleanWhether to handle namespace prefixes.

Returns SObjectField — The SObjectField, or null if not found.

Example

apex
UTIL_SObjectDescribe describe = UTIL_SObjectDescribe.getDescribe('Contact');
SObjectField field = describe.getFields().get('AccountId', false);
// field is Contact.AccountId

keySet ​

apex
global override Set<String> keySet()

Returns the key set of the map with namespace handling disabled by default.

Returns String — A set of keys in the map.

Example

apex
Set<String> result = instance.keySet();
apex
global override Set<String> keySet(Boolean implyNamespace)

Returns the key set of the map with optional namespace handling.

Parameters

ParameterTypeDescription
implyNamespaceBooleanWhether to strip namespace prefixes from keys.

Returns String — A set of keys in the map.

Example

apex
Set<String> result = instance.keySet(true);

size ​

apex
global override Integer size()

Returns the number of entries in the map.

Returns Integer — The size of the map.

Example

apex
Integer result = instance.size();

values ​

apex
global List<SObjectField> values()

Returns a token for every field on the object, whatever its namespace. To find one field by name, use get or containsKey instead.

Returns SObjectField — A list of SObjectField instances.

Example

apex
UTIL_SObjectDescribe describe = UTIL_SObjectDescribe.getDescribe('Account');
List<SObjectField> fields = describe.getFields().values();
// fields holds one token for each field on Account