Mar 6, 2012

How To Find Out If Chatter Is Enabled

Update 3/14/2012: Click here for a better way to find out if chatter is enabled.

I was asked yesterday what is the best way to figure out if a user has access to chatter. Since there is no single setting for the user/org/profile that is accessible and gives you the answer, you need to look somewhere else. In this case, the best way to get the answer would be to check if the user has access to the FeedItem object (the object that holds all the chatter posts) by using a describe method.

Here is what the code looks like if you if you need this in an apex class:

public boolean getChatterEnabled() {
    boolean ret = false;
    Map describe = Schema.getGlobalDescribe();
    if (describe.containsKey('FeedItem'))
        ret = true;
    return ret;
}

With the API, you can just query the FeedItem table - if you get an exception, the user has no access to Chatter. If you want something cleaner, The equivalent describe code through the API should look something like this: (java)

public boolean getChatterEnabled() {
    boolean ret = false;
    DescribeGlobalResult dgr = connection.describeGlobal();
    DescribeGlobalSObjectResult[] res = dgr.getSobjects();
    for (int i = 0; i < res.length; i++) {
        if (res[i].getName() == "FeedItem") {
            ret = true;
            break;
        }
    }
    return ret;
}