Record API in AfterInsert
Record
Type: TriggerHandler.InsertRecord. Predicates read the new row and never throw on null.
| Method | In AfterInsert |
|---|---|
getId() | the record Id |
getNewSObject() | the Trigger.new row, read-only |
getNewParent(relationshipName) | the parent loaded by ParentQuery, or null |
getRelated(providerName) | rows from a RelatedQuery provider |
put(field, value) | compiles, but throws System.FinalException: the row is read-only |
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 |
Records
Type: TriggerHandler.InsertRecords, passed to RecordsProvider.query (every record in the chunk), dispatchOnAfterInsert (the qualified records) and finalizeAfterInsert (the qualified records).
| Method | In AfterInsert |
|---|---|
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 ParentQuery |
getValuesOf(field) | non-null values of a field, as text |
getValuesOf(relationshipName, field) | values of a field of a parent loaded by ParentQuery, as text |
getRecords() | the records, as InsertRecord |
size() | the number of records |
Good to Know
- Ids are set. Key maps by
getId(), and passrecords.getIds()to async work. putfails the insert. Nothing catches the exception, not even ContinueOnError. RegistertoUpdatewith the record Id in a Writer instead.- Reject with the row.
record.getNewSObject().addError(…)fails that record like a validation error. getRecords()is the library's list. Removing items changes what the Finalizer receives.
