This is semi-related to another question of mine: Is there any way to clean up redundant tabs/settings/pages/etc from managed packages? However, it is a bit different.

Once you've added a global method to a managed package that has hit production you can no longer remove it or rename it (as far as I can tell). What then are your options for deprecating it if it has become obsolete?


You can deprecate the method by using the @deprecated annotation:

global static void MyMethood(){

This will prevent new subscribers of your package from seeing that method.

Existing subscribers, however, will still be able to access the method.


What I've done is changed the method body to throw an exception. Obviously, you'd want to warn people using the package that this is coming before they update so they can prepare for it.

Salesforce does not allow you to create system defined exceptions, so first you have to create your own:

public class MyManagedPackageException extends Exception {}

You can then throw this custom exception in your deprecated global methods:

    global static void MyMethod(){
        throw new MyManagedPackageException('This method is deprecated and can no longer be used. Please contact support if you have any questions regarding this method.');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.