[SalesForce] Unable to deploy trigger for triggered sends to activate

Recently we've tried to deploy a trigger via change sets to enable triggered sends within our Salesforce core production instance. Unfortunately we are only able to deploy the trigger as inactive, but are unable to activate it with a subsequent change set.

When trying to validate the change set we receive an Apex test failure error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, eventlogsTriggeredSends: execution of AfterInsert caused by: et4ae5.MCBaseException.InvalidParameterException: Whoops! Marketing Cloud Connect does not have access to the selected object. Contact your administrator to enable objects for Marketing Cloud Connect triggered sends. Class.et4ae5.triggerUtility.automate: line 30, column 1 Trigger.eventlogsTriggeredSends: line 3, column 1: []
Stack Trace: Class.Test_eventlogsTriggerSends.myUnitTest: line 13, column 1

We receive this error in spite of the object being enabled for triggered sends within the Marketing Cloud Connector Settings. To rule this out as being the cause of the error, we enabled ALL available objects for triggered sends, but still receive the same error.

  • Trigger:

    trigger eventlogsTriggeredSends on Event_Logs__c (after insert,after update)
    {
    et4ae5.triggerUtility.automate('Event_Logs__c');
    }
    
  • Test Class:

    @isTest 
    private class Test_eventlogsTriggerSends {
    
        static testMethod void myUnitTest() {
            // TO DO: implement unit test
            Account testAccount = new Account(LastName = 'Test Account', PersonEmail = 'help@fanmailmarketing.com');
            insert testAccount;
            Event_Logs__c el = new Event_Logs__c();
            el.member__c = testAccount.id;
            el.event_subtype__c = 'Marginal';
            el.event_type__c = 'Cancellation';
            el.utility_type__c = 'Electricity';
            insert el;
        }
    }
    

We've also made sure that our connector is updated to the latest version.

Best Answer

There is an issue with Marketing cloud triggers giving InvalidParameterException in test classes, the issue has been since ages so I think you have to go with the workaround.

You have to bypass eventlogsTriggeredSends using Test.isRunningTests();

trigger eventlogsTriggeredSends on Event_Logs__c (after insert,after update)
{
    if (!Test.isRunningTest()){
         et4ae5.triggerUtility.automate('Event_Logs__c');
      }
}

You can read more about this issue here: SRC: Marketing Cloud Triggered Send

SRC: https://developer.salesforce.com/forums/?id=906F0000000MJ6u

Related Topic