1

I've create the following method:

//@NotForProduction
public class TEST_SandboxDataFactory {
    public static void create() {
        List<String> sObjectTypeNameList = new List<String>();
        for (SObjectType sObjectType : XFTY_DummySObjectFactoryOutletLookup.OUTLET_TYPE_BY_SOBJECT_TYPE.keySet()){
            sObjectTypeNameList.add(sObjectType.getDescribe().getName());
        }
        System.System.debug('########### sObjectTypeNameList:' + sObjectTypeNameList);
        DummyDataCreationEventTriggerHandler.publish(sObjectTypeNameList);
    }
}

I have the following trigger:

trigger DummyDataCreationEventTrigger on DummyDataCreationEvent__e (after insert) {
    System.System.debug('########### DummyDataCreationEventTrigger:' + Trigger.new);
    DummyDataCreationEventTriggerHandler.Instance.handleTrigger();
}

and this trigger handler:

public class DummyDataCreationEventTriggerHandler extends TriggerHandler {
    XAP_TRIG_TriggerWrapper triggerWrapper;

    private DummyDataCreationEventTriggerHandler(XAP_TRIG_TriggerWrapper triggerWrapper) {
        this.triggerWrapper = triggerWrapper;
    }

    private DummyDataCreationEventTriggerHandler() {
        this(new XAP_TRIG_TriggerWrapper());
    }

    public static DummyDataCreationEventTriggerHandler instance {
        get {
            return new DummyDataCreationEventTriggerHandler();
        }
        private set;
    }

    private static final String SEPARATOR = '\n';

    public static void publish(List<String> sObjectTypeList) {
        System.System.debug('########### sObjectTypeList:' + sObjectTypeList);
        Database.SaveResult result = EventBus.publish(new DummyDataCreationEvent__e(
                SObject_Types__c = String.join(sObjectTypeList, SEPARATOR)
        ));
        System.System.debug('########### result:' + result);
    }

    protected override void handleAfterInsert() {
        List<DummyDataCreationEvent__e> dummyDataCreationEventList
                = (List<DummyDataCreationEvent__e>) this.triggerWrapper.newSObjectList;
        System.System.debug('########### dummyDataCreationEventList:' + dummyDataCreationEventList);

        List<String> sObjectTypeList = new List<String>();
        for (DummyDataCreationEvent__e dummyDataCreationEvent: dummyDataCreationEventList) {
            String sObjectTypeListString = dummyDataCreationEvent.SObject_Types__c;
            sObjectTypeList.addAll(sObjectTypeListString.split(SEPARATOR));
        }

        Schema.SObjectType sObjectType = Schema.getGlobalDescribe().get(sObjectTypeList.remove(0));
        System.System.debug('########### sObjectType:' + sObjectType);

        try {
            new XFTY_DummySObjectSupplier(sObjectType)
                    .setQuantityPerTemplate(10)
                    .setInclusivity(XFTY_InsertInclusivityEnum.ALL)
                    .setInsertMode(XFTY_InsertModeEnum.NOW_BEST_EFFORT)
                    .supplyBundle();
        }
        catch (Exception ex) {
            System.debug(LoggingLevel.ERROR, '!!! Failed to create data for ' + sObjectType);
        }

        if (!sObjectTypeList.isEmpty()) {
            publish(sObjectTypeList);
        }
    }
}

The trigger framework is known to work as expected, even if there are some silly things about it.

My expectation is that when I anonymously execute

TEST_SandboxDataFactory.create();

The system will:

  1. Publish instance of DummyDataCreationEvent__e.
  2. DummyDataCreationEventTriggerHandler.handleAfterInsert() will then:
  3. Extract sObjectTypeList from the instance of DummyDataCreationEvent__e.
  4. Pop the first SObjectType out of List sObjectTypeList
  5. Create data for SObjectType
  6. If sObjectTypeList has remaining items, publish a new instancew of DummyDataCreationEvent__e
  7. Repeat 2 through 5 until the list is exhausted.

In actuality, the trigger never seems to run and my log displays:

21:01:11.855 (6811905198)|USER_DEBUG|[8]|DEBUG|########### sObjectTypeNameList:(Account, Account_Channel__c, Acc_Channel_and_Item_Group_Connection__c, Account_and_Item_Group_Connection__c, Adyen_Payment_Line__c, Adyen_Payment_Transaction__c, Agent__c, Apparels_sizes_order__c, APXT_CMQR__Conga_Merge_Query__c, ATP__c, ...) 21:01:12.857 (6857679135)|USER_DEBUG|[22]|DEBUG|########### sObjectTypeList:(Account, Account_Channel__c, Acc_Channel_and_Item_Group_Connection__c, Account_and_Item_Group_Connection__c, Adyen_Payment_Line__c, Adyen_Payment_Transaction__c, Agent__c, Apparels_sizes_order__c, APXT_CMQR__Conga_Merge_Query__c, ATP__c, ...) 21:01:12.857 (6878399052)|USER_DEBUG|[26]|DEBUG|########### result:Database.SaveResult[getErrors=(Database.Error[getFields=();getMessage=3375d195-791e-4e58-b77e-f5c23929c4c6;getStatusCode=OPERATION_ENQUEUED;]);getId=e02xx0000000001AAA;isSuccess=true;]

I find it utterly bizarre that this log contains "isSuccess=true" within a list of Database.Error.

Any ideas what might be going wrong here and how to fix it?

7

The code/transaction run by a Platform Event Trigger is run as the "Automated Process" User, and won't show up in logs unless you specifically set up a debug log for the "Automated Process" traced entity type.

| improve this answer | |
  • Can you please include more specific directions how to set up a debug log for the "Automated Process" traced entity type? – Brian Kessler Jul 26 '19 at 19:36
  • @BrianKessler It's literally just going to the debug logs page in setup, setting up a new user trace flag, and selecting "Automated Process" from a picklist. – Derek F Jul 26 '19 at 19:59
  • Found it, thanks. :-) ... but I don't think the system is actually getting so far as to do anything with the automated processes... no logs. – Brian Kessler Jul 26 '19 at 21:30
  • Never mind... it seems to be working now.... (all of it.) :-) – Brian Kessler Jul 26 '19 at 21:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.