Find your content:

Search form

You are here

How to handle Managed package System.LicenseException on Expired Trial installs?


We have developed a managed package application which is currently privately listed in AppExchange and is soon to me made public. Our trial users have installed our application in their production orgs. Now after their trial install expires, the scheduled jobs created by the application throw System.LicenseException.

Does anyone out here has the information about how to handle this exception and possibly remove the scheduled job using code when trial has expired?

Attribution to: Mustafa Turab Ali

Possible Suggestion/Solution #1

The best way to solve this depends on the nature / importance of the scheduled jobs being created by your application, and on how you're dynamically scheduling these jobs.

The best solution, if possible, is to have a non-packaged version of the Schedulable class, in addition to the Scheduled class, that you provide along with your application. Obviously this is a lot easier with Trialforce orgs, if this is an option, but depending on how annoying the LicenseException error is, it might be worth it. What you can do is to check for a local version of your Schedulable class, with the same name, and try to use that if it exists, otherwise default to the packaged version:

// First, check to see if the running user is licensed to the acme package.
// If not, do nothing else
if (!UserInfo.isCurrentUserLicensed('acme')) {
   // OPTIONAL - may be helpful in your scenario
   // System.abortJob(jobId)

   // Do nothing more

// Get a schedulable class to run
System.Type t;
Schedulable c;
try {

    // First, check the local namespace
    // In Trialforce orgs, this class will exist
    t = System.Type.forName(null,'MySchedulableClass');

    // Second, check for an instance of this class
    // in our namespace (e.g. 'acme')
    if (t == null || String.valueOf(t).contains('null')) {
        t = System.Type.forName('acme','MySchedulableClass');

    // If we found an available Schedulable class, use it!  
    if (t != null && !String.valueOf(t).contains('null')) {
        c = (Schedulable) System.JSON.deserialize('{}',t);
} catch (Exception e) {}

// If we found a Schedulable class, schedule it to run
if (c != null) {

This is probably the best solution if you are only scheduling your job once, or if you do not have a chance to dynamically reschedule it later.

The really difficult thing about all of this is that you'll get the LicenseException from ANY code you have pre-packaged in your managed app, so even scheduling a job to run 31 days after the install to check if the user is still licensed will not help, because that job will be run using code in the package, which leaves you in the same place you started.

Attribution to: zachelrath

Possible Suggestion/Solution #2

If what you are doing is trying to detect the exception before it exists you could use the static method


This would by inference allow you to determine whether the package has expired. Be careful though, it could still return false when the package is active but the running user is not a licensed user.


As pointed out by @zachelrath, This solution is only useful if your scheduled apex class is outside the managed package. The license limit exception is thrown before the scheduled job is executed.

Attribution to: Daniel Blackhall
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content