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:
- Publish instance of DummyDataCreationEvent__e.
- DummyDataCreationEventTriggerHandler.handleAfterInsert() will then:
- Extract sObjectTypeList from the instance of DummyDataCreationEvent__e.
- Pop the first SObjectType out of List sObjectTypeList
- Create data for SObjectType
- If sObjectTypeList has remaining items, publish a new instancew of DummyDataCreationEvent__e
- 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?