4

Why is it that this will not compile:

trigger AccountChangeTrigger on AccountChangeEvent (after insert) {
    String dmlType = Trigger.new[0].ChangeEventHeader.changetype;
    ...

A non foreign key field cannot be referenced in a path expression: ChangeEventHeader

But this will:

trigger AccountChangeTrigger on AccountChangeEvent (after insert) {
    EventBus.ChangeEventHeader header = Trigger.new[0].ChangeEventHeader;
    String dmlType = header.changetype;
    ...

(As will this:

trigger AccountChangeTrigger on AccountChangeEvent (after insert) {
    String dmlType = Trigger.new[0].ChangeEventHeader.getChangeType();
    ...

)

I would have thought the compiler would treat (1) and (2) the same way, especially since Trigger.new[0] is always an instance of EventBus.ChangeEventHeader (instanceof check confirms this).

Relatedly, I haven't been able to locate the documentation on what type of object or base class is behind AccountChangeEvent (and other ___ChangeEvent objects).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.