> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fusioncore.us/llms.txt
> Use this file to discover all available pages before exploring further.

# Utility Functions

> The shared FCORE_BASE collection, validation, describe, and LWC helpers fusionCore code reaches for constantly.

These are the smaller shared utilities the Platform package (`FCORE_BASE`) exposes to subscriber and other-package code under the `FCORE_BASE` namespace — the collection, validation, describe, and LWC helpers you reach for constantly in trigger and service code. Reference them with their namespaced names (for example `FCORE_BASE.ObjectUtils`).

The bigger pieces have their own pages: [Logging](/developer-guide/logging), [Caching](/developer-guide/caching), and [DB Classes](/developer-guide/db-classes). For the surrounding frameworks, see the [Trigger Framework](/developer-guide/trigger-framework), the [Event Framework](/developer-guide/event-framework), and [Services](/developer-guide/services).

## List and Set Manipulation

`FCORE_BASE.ObjectUtils` and `FCORE_BASE.StringUtils` collect the collection helpers you reach for constantly in trigger and service code. All methods listed are `global static`.

| Operation                                   | Method                                                          | Returns                  |
| ------------------------------------------- | --------------------------------------------------------------- | ------------------------ |
| Extract record Ids                          | `ObjectUtils.getIds(List<SObject> records)`                     | `Set<Id>`                |
| Extract Ids from any Id field               | `ObjectUtils.getIdsFromList(records, 'AccountId')`              | `Set<Id>`                |
| Group records by Record Type                | `ObjectUtils.getRecordsByRecordTypeId(records)`                 | `Map<Id, List<SObject>>` |
| Find Ids missing from a map                 | `ObjectUtils.getIdsNotInMap(idsToCheck, mapToCheck)`            | `Set<Id>`                |
| Detect a field change in a trigger          | `ObjectUtils.isFieldChanged(newRec, oldRec, Account.Name)`      | `Boolean`                |
| Convert `SObjectField`s to a field-name CSV | `ObjectUtils.getFieldNamesFromSObjectFields(Set<SObjectField>)` | `String`                 |
| Validate field names (incl. dot notation)   | `ObjectUtils.validateSObjectFields(SObjectType, Set<String>)`   | `Set<String>`            |
| Split a CSV string                          | `StringUtils.splitValueWithComma(value)`                        | `List<String>`           |

```java theme={null}
Set<Id> accountIds = FCORE_BASE.ObjectUtils.getIdsFromList(contacts, 'AccountId');

if (FCORE_BASE.ObjectUtils.isFieldChanged(newAccount, oldAccount, Account.Name)) {
    // Name changed in this trigger context
}
```

## Other Notable Utilities

### Validation — `FCORE_BASE.ValidationUtils`

Guard required inputs and surface consistent messages.

* `validateIsNotNull(Object value, String name)` — throws if `value` is null, naming the offending argument.
* `validateFieldIsNotNull(SObject record, SObjectField field)` — throws if the field is null on the record.
* `buildRequiredFieldIsMissingMessage(SObjectField field)` — builds the standard "required field is missing" message.

### Describe Lookups — `FCORE_BASE.FieldDescribe`

Cached field-describe access so you do not repeat describe calls.

* `getFieldDescribe(String objectName, String fieldName)`
* `isAllowedPicklistValue(Schema.SObjectField field, String value)`
* `trimFieldValue(Schema.SObjectField field, String value)`

### Org-Timezone Datetimes — `FCORE_BASE.DateUtils`

Use `FCORE_BASE.DateUtils.getInstance().getOrganizationDatetime()` when you need a datetime in the org's timezone rather than GMT.

### Aura/LWC Error Surfacing — `FCORE_BASE.AuraUtils` and `FCORE_BASE.LabelUtils`

For consistent error handling out of `@AuraEnabled` controllers:

* `FCORE_BASE.AuraUtils.throwAuraHandledException(String message)` — throws an `AuraHandledException` the client can read.
* `FCORE_BASE.LabelUtils.buildGenericErrorMessageForContext(String context)` — a generic, context-tagged error message.
* `FCORE_BASE.LabelUtils.buildErrorMessageForContext(String context, String error)` — a context-tagged message that includes the specific error.

```java theme={null}
@AuraEnabled
public static void save(Id recordId) {
    try {
        // ... work ...
    } catch (Exception ex) {
        throw FCORE_BASE.AuraUtils.throwAuraHandledException(
            FCORE_BASE.LabelUtils.buildErrorMessageForContext('save', ex.getMessage())
        );
    }
}
```

### LWC Utilities

Import these from the `FCORE_BASE` namespace in Lightning web components:

* `toastUtils` — `showSuccessToast(...)` and `showErrorToast(...)` for consistent toast notifications.
* `ldsUtils` — `reduceErrors(error)` flattens a server/LDS error into a readable message list.
* `deviceUtils` — `isMobile()` reports whether the component is running on a mobile device.
