Is there anyway we can find all Objects which have Activities enabled, in APEX?


The most accurate and quickest way is to loop over the list of valid target Objects of the WhatId field on the Task or Event object, as this list will change whenever you check/uncheck the "Allow Activities" checkbox on a given Object:

Set<Schema.SObjectType> objectsWithActivitiesEnabled = new Set<Schema.SObjectType>();
String objectNames = '';
for (Schema.SObjectType objectType : Task.WhatId.getDescribe().getReferenceTo()) {
   objectNames += '\n' + objectType;

  • haha, this is way simpler than my method. I thought there was something like getreferenceTo but I must have missed it when I was checking the documentation. Feb 18 '13 at 18:32
  • Thanks guys. This worked. But i guess there should be some standard approach to gather Activity enabled objects from DescribesObjectresult methods.
    – VarunC
    Feb 18 '13 at 22:38
  • I would argue that this is the standard approach. From an API perspective, all that "enabling Activities on an Object" does is add a given SObject to the list of possible endpoints of the Polymorphic WhatId field common to both the Task and Event Objects. All other areas of the Salesforce API, I believe, read from this list when determining which Objects to present Activity-related functionality for, e.g. the various Activities related lists, the list of drop-down options next to the "Related To" field. And this list is precisely the content of the getReferenceTo() list given above.
    – zachelrath
    Feb 18 '13 at 23:11

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.