Find your content:

Search form

You are here

How do you deprecate a global method in a managed package?

 
Share

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?


Attribution to: Ryan Elkins

Possible Suggestion/Solution #1

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.');
    }

Attribution to: Ryan Elkins

Possible Suggestion/Solution #2

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

@deprecated
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.


Attribution to: rycornell
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/454

My Block Status

My Block Content