1

I created an Apex CDC Trigger on the ActionCadenceTracker object via the ActionCadenceTrackerChangeEvent to update a Lead's status when the sales cadence is completed. I'd like to write Apex test code for this but can't figure out how to create the Sales Cadence records. When I try to create the ActionCadenceTracker record in Apex, I get a "DML operation INSERT not allowed on ActionCadenceTracker" error. The documentation says one has to assign a prospect to a Sales Cadence but only gives declarative options and the one Apex example given shows to call out to a Salesforce API.

The automation is similar to this Salesforce lead status sample automation but uses the ActionCadenceTracker object.

Is this possible?

2 Answers 2

2

After no responses here or elsewhere, I contacted Salesforce. They mentioned that it's currently not possible to create test code for an Apex Trigger on the ActionCadenceTrackerChangeEvent because one can't generate the Action Cadence Tracker records via Apex. Support mentioned they can temporarily remove the production test code requirement so untested code can be deployed to production. They give you a time frame where production changes don't require test code and the changes are deployed then. The support rep wasn't sure if one would have to do this for every future code deployment so caution is warranted.

1

You cannot create ActionCadenceTracker record in apex but in case you want to get Code Coverage without actually Inserting Cadence record try this it worked for me to get the code coverage when I wrote the trigger on ActionCadenceChangeEvent

Contact con = [SELECT Id FROM Contact LIMIT 1];
String jsonObject = '[{
    "attributes": {
        "type": "ActionCadenceTracker",
        "url": "/services/data/v56.0/sobjects/ActionCadenceTracker/0qB76000000GzO4EAK"
    },
    "Id": "0qB76000000GzO4EAK",
    "OwnerId": "005760000010oRMAAY",
    "CreatedDate": "2022-10-04T05:42:52.000+0000",
    "CreatedById": "005760000010oRMAAY",
    "ActionCadenceId": "77C760000004CBEEA2",
    "TargetId": "'+con.Id +'"
}]';
List<ActionCadenceTracker> cadenceList = (List<ActionCadenceTracker>)JSON.deserialize(jsonObject, List<ActionCadenceTracker>.class); 

Here Target was set on Contact Record that's why I have used ContactId in Target Id you can use the Id of the record which is being set as Target in Cadence Now you can utilize this list cadenceList to pass it to any method in Apex test class which requires ActionCadenceTracker record

PS - I have used JSON because you cannot write the fields of Action Cadence Tracker by creating the object of it Dev console shows error of "FIELD NOT WRITEABLE"

1
  • How did you get your cadenceList through to the underlying CDC trigger? Oct 28, 2022 at 19:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .