Skip to content

Record API in BeforeUpdate

Record

Type: TriggerHandler.UpdateRecord. Predicates read the new row and never throw on null.

MethodIn 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), isRecordTypeNotEqualrecord type developer name matches / differs
equals(field, value), doesNotEqualequal / different; text ignores case
contains(field, value), doesNotContain, startsWith, endsWithtext match; case-sensitive
isNull(field), isNotNullnull / not null
isEmpty(field), isNotEmptynull or '' / neither
isBlank(field), isNotBlanknull, '' or whitespace / none
isTrue(field), isFalsetrue / false
greaterThan(field, value), greaterThanOrEqualTo, lessThan, lessThanOrEqualTonumber 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), isChangedFromchanged 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).

MethodIn 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, call record.getNewSObject().addError(…).