Skip to content

UTIL_BulkUpdates

Class · Group: Bulk DML

apex
global inherited sharing class UTIL_BulkUpdates

Utility methods used to initialize adaptive async jobs to update fields on multiple objects. Provides methods for bulk updating Salesforce records, such as invalidating email fields, updating ownership, and deactivating users. Operations are performed using adaptive async processing which automatically selects between Queueable and Batch execution based on data volume and governor limits. All entry points inherit the flag-driven default AccessLevel resolved by DML_SharingProxy.defaultAccessLevel() — under the secure-by-default posture this is USER_MODE, so the invoking user must have CRUD and FLS on the target object and fields for the bulk update to succeed. This is deliberate: UTIL_BulkUpdates is global, and silently elevating to SYSTEM_MODE would let a low-privilege subscriber Apex caller mutate records and fields they have no native right to edit. Integrations that genuinely need admin-mandate semantics should construct a PROC_UpdateFields directly with DTO_Parameters.accessLevel = AccessLevel.SYSTEM_MODE behind a caller-side permission check; the framework declines to make that elevation implicit.

Example

apex
UTIL_BulkUpdates.invalidateEmailFields(Contact.Email);
UTIL_BulkUpdates.updateOwner('Opportunity', 'Sales Rep', 'admin@example.com');
UTIL_BulkUpdates.deactivateUsers(new Set<String>{'Chatter Free User'}, 365);

See Also: PROC_UpdateFields


Methods

MethodDescription
global static void deactivateUsers(Set<String> profileNames, Integer minimumDaysInactive)Deactivates users based on their profile names and the number of days since their last login or creation.
global static void deactivateUsers(Set<String> profileNames, Integer minimumDaysInactive, Boolean isAllOrNothing)Deactivates users based on their profile names and last login or creation date, with transaction control.
global static void deactivateUsers(Set<String> profileNames, Integer minimumDaysInactive, Integer recordsPerBatch, Boolean isAllOrNothing)Deactivates users based on their profile names and last login or creation date, with custom batch size and transaction control.
global static void invalidateEmailFields(SObjectField emailFieldToInvalidate)Invalidates all valid email addresses for the specified email field.
global static void invalidateEmailFields(SObjectField emailFieldToInvalidate, Integer recordsPerBatch)Invalidates all valid email addresses for the specified email field, with a custom batch size.
global static void invalidateEmailFields(SObjectField emailFieldToInvalidate, Integer recordsPerBatch, Boolean isAllOrNothing)Invalidates all valid email addresses for the specified email field, with batch size and transaction control.
global static void invalidateEmailFields(String sObjectName, String fieldApiName)Invalidates all valid email addresses for the specified field in a Salesforce object.
global static void invalidateEmailFields(String sObjectName, String fieldApiName, Boolean isAllOrNothing)Invalidates all valid email addresses for the specified field in a Salesforce object, with transaction control.
global static void invalidateEmailFields(String sObjectName, String fieldApiName, Integer recordsPerBatch, Boolean isAllOrNothing)Invalidates all valid email addresses for the specified field in a Salesforce object, with custom batch size and transaction control.
global static void updateField(String sObjectName, String fieldApiName, Object fieldValue, QRY_Condition.Evaluable searchConditions, Integer recordsPerBatch, Boolean isAllOrNothing)Updates a specific field on records in a Salesforce object based on the given search conditions.
global static void updateOwner(String sObjectName, String existingOwnerProfileName, String newOwnerUsername)Updates the ownership of records based on the existing owner profile name and new owner username.
global static void updateOwner(String sObjectName, String existingOwnerProfileName, String newOwnerUsername, Integer recordsPerBatch, Boolean isAllOrNothing)Updates the ownership of records based on the current owner profile, new owner username, batch size, and transaction control.

deactivateUsers

apex
global static void deactivateUsers(Set<String> profileNames, Integer minimumDaysInactive)

Deactivates users based on their profile names and the number of days since their last login or creation. Uses the maximum batch size for processing.

Parameters

ParameterTypeDescription
profileNamesSetThe profile names of the users to deactivate.
minimumDaysInactiveStringThe minimum number of days since their last login or creation.

Example

apex
Set<String> profiles = new Set<String>{'Sales Rep', 'Support Rep'};
UTIL_BulkUpdates.deactivateUsers(profiles, 365);
apex
global static void deactivateUsers(Set<String> profileNames, Integer minimumDaysInactive, Boolean isAllOrNothing)

Deactivates users based on their profile names and last login or creation date, with transaction control.

Parameters

ParameterTypeDescription
profileNamesSetThe profile names of the users to deactivate.
minimumDaysInactiveStringThe minimum number of days since their last login or creation.
isAllOrNothingIntegerWhether to abort the operation if any record fails.

Example

apex
Set<String> profiles = new Set<String>{'Support Rep'};
UTIL_BulkUpdates.deactivateUsers(profiles, 180, true);
apex
global static void deactivateUsers(Set<String> profileNames, Integer minimumDaysInactive, Integer recordsPerBatch, Boolean isAllOrNothing)

Deactivates users based on their profile names and last login or creation date, with custom batch size and transaction control.

Parameters

ParameterTypeDescription
profileNamesSetThe profile names of the users to deactivate.
minimumDaysInactiveStringThe minimum number of days since their last login or creation.
recordsPerBatchIntegerThe number of records to process in each batch.
isAllOrNothingIntegerWhether to abort the operation if any record fails.

Example

apex
Set<String> profiles = new Set<String>{'Sales Rep'};
UTIL_BulkUpdates.deactivateUsers(profiles, 90, 200, false);

invalidateEmailFields

apex
global static void invalidateEmailFields(SObjectField emailFieldToInvalidate)

Invalidates all valid email addresses for the specified email field. Uses the maximum batch size for efficient processing.

Parameters

ParameterTypeDescription
emailFieldToInvalidateSObjectFieldThe email field to query and invalidate in records.

Example

apex
SObjectField emailField = Account.Email;
UTIL_BulkUpdates.invalidateEmailFields(emailField);
apex
global static void invalidateEmailFields(SObjectField emailFieldToInvalidate, Integer recordsPerBatch)

Invalidates all valid email addresses for the specified email field, with a custom batch size.

Parameters

ParameterTypeDescription
emailFieldToInvalidateSObjectFieldThe email field to query and invalidate.
recordsPerBatchIntegerThe number of records to process in each batch.

Example

apex
SObjectField emailField = Contact.Email;
UTIL_BulkUpdates.invalidateEmailFields(emailField, 200);
apex
global static void invalidateEmailFields(SObjectField emailFieldToInvalidate, Integer recordsPerBatch, Boolean isAllOrNothing)

Invalidates all valid email addresses for the specified email field, with batch size and transaction control. If isAllOrNothing is true, the entire transaction is rolled back if any record fails.

Parameters

ParameterTypeDescription
emailFieldToInvalidateSObjectFieldThe email field to query and invalidate.
recordsPerBatchIntegerThe number of records to process in each batch.
isAllOrNothingBooleanWhether to abort the transaction on failure (true = abort on any failure).

Example

apex
SObjectField emailField = Lead.Email;
UTIL_BulkUpdates.invalidateEmailFields(emailField, 100, true);
apex
global static void invalidateEmailFields(String sObjectName, String fieldApiName)

Invalidates all valid email addresses for the specified field in a Salesforce object. Uses the maximum batch size for processing.

Parameters

ParameterTypeDescription
sObjectNameStringThe name of the Salesforce object (e.g., 'Account').
fieldApiNameStringThe API name of the field (e.g., 'Email') to check and invalidate.

Example

apex
UTIL_BulkUpdates.invalidateEmailFields('Account', 'Email');
apex
global static void invalidateEmailFields(String sObjectName, String fieldApiName, Boolean isAllOrNothing)

Invalidates all valid email addresses for the specified field in a Salesforce object, with transaction control.

Parameters

ParameterTypeDescription
sObjectNameStringThe name of the Salesforce object (e.g., 'Opportunity').
fieldApiNameStringThe API name of the field (e.g., 'Email') to check and invalidate.
isAllOrNothingBooleanWhether to abort the transaction on failure.

Example

apex
UTIL_BulkUpdates.invalidateEmailFields('Opportunity', 'Email', true);
apex
global static void invalidateEmailFields(String sObjectName, String fieldApiName, Integer recordsPerBatch, Boolean isAllOrNothing)

Invalidates all valid email addresses for the specified field in a Salesforce object, with custom batch size and transaction control.

Parameters

ParameterTypeDescription
sObjectNameStringThe name of the Salesforce object (e.g., 'Case').
fieldApiNameStringThe API name of the field (e.g., 'Email') to check and invalidate.
recordsPerBatchIntegerThe number of records to process in each batch.
isAllOrNothingBooleanWhether to abort the transaction on failure.

Example

apex
UTIL_BulkUpdates.invalidateEmailFields('Case', 'Email', 500, false);

updateField

apex
global static void updateField(String sObjectName, String fieldApiName, Object fieldValue, QRY_Condition.Evaluable searchConditions, Integer recordsPerBatch, Boolean isAllOrNothing)

Updates a specific field on records in a Salesforce object based on the given search conditions. Processes updates in batches with control over partial transaction behavior.

Parameters

ParameterTypeDescription
sObjectNameStringThe name of the Salesforce object (e.g., 'Opportunity').
fieldApiNameStringThe API name of the field to update.
fieldValueObjectThe new value to set for the field.
searchConditionsQRY_Condition.EvaluableThe conditions used to find the records to update.
recordsPerBatchIntegerThe number of records to process in each batch.
isAllOrNothingBooleanWhether to abort the transaction on failure.

Example

apex
QRY_Condition.Evaluable condition = new QRY_Condition.AndCondition()
		.add(new QRY_Condition.FieldCondition('Status').equals('Closed'));
UTIL_BulkUpdates.updateField('Opportunity', 'OwnerId', '005D0000001ABCD', condition, 100, false);

updateOwner

apex
global static void updateOwner(String sObjectName, String existingOwnerProfileName, String newOwnerUsername)

Updates the ownership of records based on the existing owner profile name and new owner username. Uses the maximum batch size for processing.

Parameters

ParameterTypeDescription
sObjectNameStringThe name of the Salesforce object (e.g., 'Opportunity').
existingOwnerProfileNameStringThe profile name of the current record owners.
newOwnerUsernameStringThe username of the new owner to assign to the records.

Example

apex
UTIL_BulkUpdates.updateOwner('Opportunity', 'Sales Rep', 'john.doe@example.com');
apex
global static void updateOwner(String sObjectName, String existingOwnerProfileName, String newOwnerUsername, Integer recordsPerBatch, Boolean isAllOrNothing)

Updates the ownership of records based on the current owner profile, new owner username, batch size, and transaction control.

Parameters

ParameterTypeDescription
sObjectNameStringThe name of the Salesforce object (e.g., 'Account').
existingOwnerProfileNameStringThe profile name of the current record owners.
newOwnerUsernameStringThe username of the new owner to assign to the records.
recordsPerBatchIntegerThe number of records to process in each batch.
isAllOrNothingBooleanWhether to abort the transaction on failure.

Example

apex
UTIL_BulkUpdates.updateOwner('Account', 'Support Rep', 'jane.smith@example.com', 200, true);