One of the biggest challenges that I face when writing my code is making sure certain things are enabled in an Org. For example some people still don’t have Chatter enabled so trying to post to a feed is going to cause my code to blow up. Each time I come across something like this I always have to go hunting to find the best way to figure out if something is on or not. This trawling of the internet finally got the better of me the other day and I have started a Feature class.
I proposed that it would be helpful if Salesforce themselves provided something like this class but here is my initial version of it, most up to date version is available over on GitHub.
Two of the properties in here Edition and IsSandbox simply pull data from the Organization object in Salesforce but I have included them in here as I can assign them to a static property and therefore give myself the luxury of being able to put this test in a loop without having to have a variable external to the loop holding the query result. Cleaner code and fewer SOQL statements: music to my ears.
The other two properties that are in the class are PersonAccounts and Chatter. PersonAccounts encapsulates a test to find out if the user has Person Accounts enable in the Org. This one is a constant bug bear for me when writing managed package code but let’s not dwell on that. Whilst Chatter will tell you if Chatter is enabled in an Org… these days this almost always returns true, but trust me every now and then it returns false. It was in fact a bug in my code caused y Chatter not being enabled that rekindled my desire to write this class.
There is a test class that goes along with this but I haven’t included it here for brevity. And the fact that it’s not really that exciting. If you want the class and test class or you want to contribute to it because I have made an awfully glaring mistake then head on over the GitHub repo.