Monday, 10 March 2014

Check Package Installation based on Name Space Prefix..

How can you ensure particular package is installed or not in your org. 

Here is some code snippet which will help you on the same.
 let say the package prefix is invoiceit_crmx.

String sExtensionNameSpace = 'invoiceit_crmx';
    Boolean isInstalled;
    try{
    if(Userinfo.isCurrentUserLicensed(sExtensionNameSpace)){
    isInstalled = true;
    }
    else{
    isInstalled = false;
    }
    }catch(Exception ex){
    isInstalled  = false;
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Please  install CRM extension package to access these records');
    ApexPages.addMessage(myMsg); 
   
        }
If package is not installed then It will through Type exception. You can handle that exception and show some valid  your own message.

No comments: