[SalesForce] Missing Organization Feature: Chatter

We created a package that uses chatter functionality. One of our users is not using chatter and disabled in their org so our package is throwing an error "Missing Organization Feature: Chatter". User is not willing to enable chatter.

Is there a way that we can write some condition if chatter is enabled do this and if not do this.

I am already checking id the chatter is enabled using the below snippet

Schema.DescribeSObjectResult R = CSTest__c.SObjectType.getDescribe();
            return R.isFeedEnabled();

In visualforce page

<chatter:feedWithFollowers entityId="{!testIdChatter}" id="chatterId" />

Is there away that we can write the functionality if the chatter is not enabled do some other stuff.

Best Answer

Unfortunately this is a hard problem without many tried and tested solutions!

Determining if chatter is enabled:

Boolean isChatterEnabled = true;
try {Type.forName('FeedItem');}
catch (System.NoAccessException e) {isChatterEnabled = false;}

//gives true/false as appropriate

Possible prevention of feature dependency in Visualforce:

<!-- try using a Dynamic Component in the VF page -->
<apex:dynamicComponent componentValue="{!DynamicChatter}" />

//this is all a wild guess
public ApexPages.Component getDynamicChatter() {
    ApexPages.Component cmp;
    if (isChatterEnabled) {
        ApexPages.Component cmp = Type.forName('Component.Apex.Chatter').newInstance();
        cmp.put('entityId', testIdChatter);
        cmp.put('id', 'chatterId');
    return cmp;

Prevention of feature dependency when performing DML using dynamic types for inserts:

if (isChatterEnabled) {
    SObject feedItem = Type.forName('FeedItem');
    feedItem.put('ParentId', UserInfo.getUserId());
    feedItem.put('Body', 'Check out my dependency free chatter post!');
    insert feedItem;

Prevention of feature dependency when querying, using dynamic SOQL:

if (isChatterEnabled) {
    Id userId = UserInfo.getUserId();
    List<SObject> myPosts = Database.query('SELECT Body FROM FeedItem WHERE Id = :userId');
Related Topic