function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ChemburChembur 

Identify if Managed or unmanaged package in an Apex Trigger

In an ApexTrigger is there a way to identify if the Trigger is being called from Managed or unmanaged Package ?

Same Trigger is called from a  Managed or Unmanaged package. Due to validation rules it fails when being called from Managed package.

I would like to check the package before calling the validation rules on the Trigger.

 

 

sfdcfoxsfdcfox

There isn't a function call for "running in managed mode" that you can use directly. But, you can use:

 

Boolean isManaged, isUserLicensed;
try {
  isUserLicensed = System.isCurrentUserLicensed('mynamespace');
  isManaged = true;
} catch(exception e) {
  isManaged = false;
}

If isManaged is true, you are executing from the managed package you named (because, if you were running from an unmanaged code where this namespace did not exist, and exception would be thrown, the line isManaged = true would not execute, but isManaged = false would). If you are in the managed package, you can then tell if the user has a license to use the app (isUserLicensed). However, using this technique, you would not be able to determine if both packages were installed (because it would report as being managed).

thesunloverthesunlover
Here is another similar question in Stack exchange: https://salesforce.stackexchange.com/questions/358829/field-names-and-namespace-for-unmanaged-and-managed-package