Skip to content

Record API in AfterDelete

Record

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

MethodIn AfterDelete
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), dispatchOnAfterDelete (the qualified records) and finalizeAfterDelete (the qualified records).

MethodIn AfterDelete
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

  • Ids without rows. getId() and getIds() return the deleted Ids, but SOQL no longer finds those rows. Key queries by getIdsOf(Contact.AccountId).
  • Lookups hold only the Id. ((Contact) record.getOldSObject()).Account is null. Declare a PriorParentQuery and read record.getOldParent('Account').
  • The old row is read-only. Writing a field on getOldSObject() throws a FinalException that cannot be caught, not even with ContinueOnError.
  • 0 and false are values. They are not null, empty or blank.
  • Record types. isRecordTypeEqual throws on an object without record types. An unknown name never matches.