Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 down vote accepted

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;

share|improve this answer
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. – Greg Grinberg 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 posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.