3

For a given Organization, how can I determine if it has the Product Schedule feature enabled without adding a dependency on that feature to a managed package?

In the UI under App Setup > Customize > Products > Schedule Setup it appears as:

Salesforce Product Schedule Enabled

1 Answer 1

2

I came up with this while phrasing the question. Alternatives or improvements are welcome.

From the Product2 documentation:

Schedules are available only for those organizations that have the products and schedules features enabled. If the organization does not have the schedules feature, the schedule fields do not appear in the DescribeSObjectResult, and you can’t query, create, or update the fields.

So...

/**
 * Are product schedules enabled for this Org?
 */
public static boolean schedulesEnabledForOrg() {
    Schema.DescribeSObjectResult describeSObjectResult = Product2.SObjectType.getDescribe();
    return describeSObjectResult.fields.getMap().containsKey('CanUseRevenueSchedule');
}

This should probably be cached at some level to prevent repeated calls to the metadata for a result that won't change very often.

3
  • 1
    It might just be easier to try{ (new Product2()).put('CanUseRevenueSchedule'); }catch(Exception e){ system.debug('nope!'); } Much faster execution and lower heap space use (although conceptually uglier). Commented Mar 6, 2013 at 3:55
  • @ca_peterson Interesting. Coming from a .NET background I've typically thought of exceptions as something to avoid as the alternative would be faster. I guess pulling the meta data can be costly. Commented Mar 6, 2013 at 6:08
  • 1
    @E.J. Wilburn tested this on a related question. The describe approach was 50% slower: salesforce.stackexchange.com/a/1056/60 Commented Mar 6, 2013 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .