Record API in BeforeUpdate
Record
Type: TriggerHandler.UpdateRecord. Predicates read the new row and never throw on null.
| Method | In BeforeUpdate |
|---|---|
getId() | the record Id |
getNewSObject() | the Trigger.new row |
getOldSObject() | the Trigger.old row, read-only |
getNewParent(relationshipName) | the parent loaded by ParentQuery, or null |
getOldParent(relationshipName) | the parent the old row pointed to, loaded by PriorParentQuery, or null |
getRelated(providerName) | rows from a RelatedQuery provider |
put(field, value) | sets a field on the Trigger.new row |
isRecordTypeEqual(recordTypeDeveloperName), isRecordTypeNotEqual | record type developer name matches / differs |
equals(field, value), doesNotEqual | equal / different; text ignores case |
contains(field, value), doesNotContain, startsWith, endsWith | text match; case-sensitive |
isNull(field), isNotNull | null / not null |
isEmpty(field), isNotEmpty | null or '' / neither |
isBlank(field), isNotBlank | null, '' or whitespace / none |
isTrue(field), isFalse | true / false |
greaterThan(field, value), greaterThanOrEqualTo, lessThan, lessThanOrEqualTo | number or date comparison; false for null |
isChanged(field) | the new value differs from the old one |
isAnyChanged(field1, field2, …), areAllChanged(field1, field2, …) | any / every field changed; 2 to 5 fields or an Iterable<SObjectField> |
isChangedTo(field, expectedValue), isChangedFrom | changed to / from the value |
isChangedFromTo(field, fromValue, toValue) | the old value is fromValue and the new one is toValue |
addErrorOnBeforeUpdate gets a TriggerHandler.RejectableUpdateRecord: no put, plus addError(error) and addError(field, error).
Records
Type: TriggerHandler.UpdateRecords, passed to RecordsProvider.query (every record in the chunk) and finalizeBeforeUpdate (the qualified records).
| Method | In BeforeUpdate |
|---|---|
getIds() | the record Ids |
getIdsOf(field) | non-null Ids in a lookup or Id field of the new row |
getIdsOf(relationshipName, field) | Ids in a field of a parent loaded by ParentQuery |
getOldIdsOf(field) | non-null Ids in a lookup or Id field of the old row |
getOldIdsOf(relationshipName, field) | Ids in a field of a parent loaded by PriorParentQuery |
getValuesOf(field) | non-null values of a field of the new row, as text |
getValuesOf(relationshipName, field) | values of a field of a parent loaded by ParentQuery, as text |
getOldValuesOf(field) | non-null values of a field of the old row, as text |
getOldValuesOf(relationshipName, field) | values of a field of a parent loaded by PriorParentQuery, as text |
getRecords() | the records, as UpdateRecord |
size() | the number of records |
Good to Know
- Changes include earlier
puts. A value that an earlier handler set counts as a change. - Text changes ignore case.
'Doe'to'DOE'is not a change. - Only the Validator gets
addError. Elsewhere, callrecord.getNewSObject().addError(…).
