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:
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.