[SalesForce] Enable SharedActivities automaticaly for new scratch org

Is there any chance to set up scratch org definition file, to create new scratch orgs with SharedActivities functionality enabled?

We just implemented some functionalities using TaskRelation object, but it fails on deployment to fresh org, because freshly created orgs has disabled SharedActivites.

For sure I edited Activities.settings file, but still, i am getting error during deployment:

You can't use the Tooling API or Metadata API to enable or disable Shared Activities. To enable this feature, visit the Activity Settings page in Setup. To disable this feature, contact Salesforce.

And SFDC docs are confirming that message, that field allowUsersToRelateMultipleContactsToTasksAndEvents

is readonly for mdapi from version 36. I was trying also lower versions but message remains the same.

This is big issue because it breaks our CI-validation process.

I am looking for any way to turn on that setting automaticaly after creating new scratch org, and before starting code deployment.

Every help much appreciated.

Best Answer

I workarounded that particular problem by switching all queries from static ones

[SELECT Id From TaskRelation];

to Strings, and use Database.query.

For new instances of TaskRelation object, I used:

Type.forName('TaskRelation').newInstance();

Thanks to that compiler/validator is not checking types on deployment and build passes.

Of course blocks of code with that workaround needs to be ommited in tests, otherwise deployment will fails anyway, due to unsuporrted type: TaskRelation.