2

I have a managed package and I wanted to create or update tasks through Apex. We also would like to include this in managed package. While researching I found that to update WhoId field of tasks through Apex when Shared Activities are enabled we have to use "TaskRelation" object.

However, if I include "TaskRelation" object into package, the package is not getting installed on the Salesforce org where "SharedActivities" feature is not enabled.

Can anybody help me out with this? How can I handle this dynamically in package?

Thanks in advance.

1

I was about to post the same question but I see you didn't get any answers so I won't repeat the question.

What I was going to suggest - and seek confirmation on - was to detect the presence of the TaskRelation object in the Schema. getGlobalDescribe results. If present, I would use dynamic code such as SObjectType.newInstance to create the TaskRelation and SObject.put to set values.. If not present I would use single who ID logic.

That should avoid any compile-time dependency on TaskRelation and so allow the managed package to install whether the feature is enabled or not.

Testing would be awkward as probably safest to not turn the feature on in the packaging org. So mistakes in the code would only be detected after packaging and installing in orgs with and without the feature enabled.

Nakul, did you solve the problem this way or some other way? Or anyone else?

0

What Keith said is correct, and is also described in the docs:

TaskRelation is only available if you’ve enabled Shared Activities in your organization. https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_taskrelation.htm

Doing a HEAD-call to /services/data/v37.0/sobjects/TaskRelation will return:

  • Status Code 200 = "Shared Activities" is enabled
  • Status Code 404 = "Shared Activities" is not enabled

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.