Skip to content

Record API in BeforeDelete

Record

Type: TriggerHandler.DeleteRecord. Predicates read the old row and never throw on null.

MethodIn BeforeDelete
getId()the record Id
getOldSObject()the Trigger.old row, read-only
getOldParent(relationshipName)the parent the old row pointed to, loaded by PriorParentQuery, or null
getRelated(providerName)rows from a RelatedQuery provider
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

Records

Type: TriggerHandler.DeleteRecords, passed to RecordsProvider.query (every record in the chunk) and finalizeBeforeDelete (the qualified records).

MethodIn BeforeDelete
getIds()the record Ids
getIdsOf(field)non-null Ids in a lookup or Id field
getIdsOf(relationshipName, field)Ids in a field of a parent loaded by PriorParentQuery
getValuesOf(field)non-null values of a field, as text
getValuesOf(relationshipName, field)values of a field of a parent loaded by PriorParentQuery, as text
getRecords()the records, as DeleteRecord
size()the number of records

Good to Know

  • Only the old row. There is no put, getNewSObject or getNewParent.
  • Read-only, but takes errors. Writing to getOldSObject() throws. getOldSObject().addError('…') blocks the delete of that record.
  • Lookups hold only the Id. ((Contact) record.getOldSObject()).Account is null. Declare a PriorParentQuery and read getOldParent('Account').
  • No merge winner yet. MasterRecordId is set only in AfterDelete.