Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 4 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()) {
   objectsWithActivitiesEnabled.add(objectType);
   objectNames += '\n' + objectType;
}

system.debug(objectNames);
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. –  Varun Chaddha 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
add comment

Your Answer

 
discard

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.