UTIL_System
Class · Group: Utilities
global inherited sharing class UTIL_SystemNamespace, type resolution, and platform utility methods. Provides runtime introspection for managed package namespace detection, class type resolution, API version retrieval, and session management.
Since: 1.0
Example:
String namespace = UTIL_System.getManagedPackageNamespace();
Type handlerType = UTIL_System.getTypeForClassName('TRG_SetFoobarDefaults');
Type validated = UTIL_System.getTypeForClassName('TRG_SetFoobarDefaults', IF_Trigger.BeforeInsert.class);Methods
| Method | Description |
|---|---|
| global static Type findTypeForClassName(String className) | Resolves a class name to a Type via the UTIL_TypeResolver chain without throwing an exception. |
| global static Type findTypeForClassName(String className, Type expectedType) | Resolves a class name to a Type via the UTIL_TypeResolver chain and verifies it is assignable to the expected type. |
| global static String getApiEnabledSessionId() | Will render a VF page to retrieve an API Enabled Session Id for current user To improve performance, session will be cached |
| global static String getClassNamespace(String className) | Will extract the namespace out of a class name, expects the class to be a top level class |
| global static String getManagedPackageNamespace() | Will determine the namespace for the current execution context; ie. |
| global static String getManagedPackageNamespacePrefix(String delimiter) | Will determine the namespace for the current execution context; ie. |
| global static String getNamespacePrefix(String namespace, String delimiter) | Will calculate namespace prefix as follows: if the namespace exists - namespace + delimiter else Empty String |
| global static String getOrgApiVersion() | Will determine the current Salesforce Org Api Version |
| global static String getRuntimeTypeName(Object anObject) | This method serves to retrieve the type name of the provided object |
| global static Type getTypeForClassName(String className) | Will return the Type for a given object class name |
| global static Type getTypeForClassName(String className, Type expectedType) | Will return the Type for a given object class name |
Method Details
findTypeForClassName
global static Type findTypeForClassName(String className)Resolves a class name to a Type via the UTIL_TypeResolver chain without throwing an exception. Returns null when the class cannot be found or has compilation errors.
Parameters:
className(String) - The class name to resolve.
Returns: Type - The resolved Type, or null if not found.
Since: 1.0
Example:
Type classType = UTIL_System.findTypeForClassName('SCHED_DeactivateUsers');findTypeForClassName
global static Type findTypeForClassName(String className, Type expectedType)Resolves a class name to a Type via the UTIL_TypeResolver chain and verifies it is assignable to the expected type. Returns null when the class cannot be found or does not implement the expected type.
Parameters:
className(String) - The class name to resolve.expectedType(Type) - The type the resolved class must be assignable to.
Returns: Type - The resolved Type, or null if not found or not assignable.
Since: 1.0
Example:
Type classType = UTIL_System.findTypeForClassName('SCHED_DeactivateUsers', Schedulable.class);getApiEnabledSessionId
global static String getApiEnabledSessionId()Will render a VF page to retrieve an API Enabled Session Id for current user To improve performance, session will be cached
Returns: String - API enabled Session Id
Since: 1.0
Example:
String sessionId = UTIL_System.getApiEnabledSessionId();getClassNamespace
global static String getClassNamespace(String className)Will extract the namespace out of a class name, expects the class to be a top level class
Parameters:
className(String) - The name of the class
Returns: String - Empty String or the namespace
Since: 1.0
Example:
String namespace = UTIL_System.getClassNamespace('kern.UTIL_System'); // 'kern'
String empty = UTIL_System.getClassNamespace('MyClass'); // ''getManagedPackageNamespace
global static String getManagedPackageNamespace()Will determine the namespace for the current execution context; ie. Is code currently running sitting in a package and the namespace of the package
Returns: String - Empty String or the package namespace
Since: 1.0
Example:
String namespace = UTIL_System.getManagedPackageNamespace(); // e.g. 'kern' or ''getManagedPackageNamespacePrefix
global static String getManagedPackageNamespacePrefix(String delimiter)Will determine the namespace for the current execution context; ie. Is code currently running sitting in a package and the namespace of the package and add the provided delimiter (if a namespace exists)
Parameters:
delimiter(String) - The delimiter for the item
Returns: String - Empty String or the namespace with prefix
Since: 1.0
Example:
// Returns 'Sfdc_Surveys.' when namespace exists with '.' delimiter
String namespaceWithDot = UTIL_System.getManagedPackageNamespacePrefix('.');
// Returns 'Sfdc_Surveys__' when namespace exists with '__' delimiter
String namespaceWithUnderscores = UTIL_System.getManagedPackageNamespacePrefix('__');
// Returns '' when namespace does not existgetNamespacePrefix
global static String getNamespacePrefix(String namespace, String delimiter)Will calculate namespace prefix as follows: if the namespace exists - namespace + delimiter else Empty String
Parameters:
Returns: String - Empty String or the namespace with prefix
Since: 1.0
Example:
String prefix = UTIL_System.getNamespacePrefix('kern', '.'); // 'kern.'getOrgApiVersion
global static String getOrgApiVersion()Will determine the current Salesforce Org Api Version
Returns: String - the version in the form of "59.0"
Since: 1.0
Example:
String version = UTIL_System.getOrgApiVersion(); // e.g. '65.0'getRuntimeTypeName
global static String getRuntimeTypeName(Object anObject)This method serves to retrieve the type name of the provided object
Parameters:
anObject(Object) - The object to evaluate
Returns: String - Name of Class of the Object provided
Since: 1.0
Example:
String typeName = UTIL_System.getRuntimeTypeName((Object)'Hello'); // 'String'getTypeForClassName
global static Type getTypeForClassName(String className)Will return the Type for a given object class name
Parameters:
className(String) - The class name to find a type for (please ensure that you prefix namespace if required)
Returns: Type - The type of the object
Throws:
- IllegalArgumentException - If no type if found for the given class name
Since: 1.0
Example:
Type classType = UTIL_System.getTypeForClassName('UTIL_System');getTypeForClassName
global static Type getTypeForClassName(String className, Type expectedType)Will return the Type for a given object class name
Parameters:
className(String) - The class name to find a type for (please ensure that you prefix namespace if required)expectedType(Type) - The expected type that the type for the class is assignable from
Returns: Type - The type of the object
Throws:
- IllegalArgumentException - If no type if found for the given class name
- TypeException - if the type is not compatible with the expected type
Since: 1.0
Example:
Type classType = UTIL_System.getTypeForClassName('UTIL_System', Object.class);