+ Start a Discussion
bozotheclownbozotheclown 

Deleting a Class - Problems

Hello.  I am trying to delete a few lines of a custom controller - via the salesforce.com section SETUP --> DEVELOP --> APEX CLASSES.  I have confirmed that I have deleted all references to these deleted lines in the rest of my controller and associated VF pages.  Unfortunately, I continue to receive the error message "This apex class is referenced elsewhere in salesforce.com. Remove the usage and try again. at line 0 column 0".  

 

I absolutely know that the deleted apex class is not referenced anywhere else in my delopymnet (VF pages, triggers, etc, etc)....so I am totally lost as to why this is happening.

 

After doing some searching on the web, I noticed a comment that you cannot delete classes...unless you do it with the migration tool.  

 

Is that my problem?  So there is no way to simply delete the line of code that references an apex class?

 

Thanks in advance.

sfdcfoxsfdcfox

"Cannot delete classes" only applies to entire classes, and only in managed packages, and only if those classes are in a released state, and are global scope classes. Removing lines from a class is just fine, so long as they are completely unreferenced elsewhere. In practice, I've found that you often need to comment out any pages that use that controller before attempting to remove functions from a class that is a controller. Try this:

 

1) Locate the pages that use the controller.

2) For each page, comment it out entirely, like this:

 

<apex:page>
</apex:page>
<!-- Original Code
<apex:page controller="myController" ...>
  ...
</apex:page>
-->

3) Remove the function(s); they should be just fine now.

4) Uncomment each page in step 2 back to their former state; you may need to fix those pages if you receive any errors.

 

bozotheclownbozotheclown

Ah ha.

 

I failed to note in my initial post that this controller is part of a managed package.

 

So does that mean that I cannot delete the class?  This seems odd to me because I can delete anything else within the controller (even though it is a released package).

 

Thanks for the help.

sfdcfoxsfdcfox

If the class is global, then you won't be able to delete it, unless you are able to roll back to a managed beta (meaning, there are no installed versions of your package that include the class). Global classes are a particular pain in a managed package; you'll have to leave it in for all time. This restriction is in place because a global class might be used outside of your package, and so therefore you could break your clients' integrations with that class. If you think you can roll back, open a case with customer support; they're the ones that can take care of that request.

bozotheclownbozotheclown

Thanks a lot.  Very much appreciated.

 

The class is public...but not global.  However, it has been in my released version from v1.0...so I do not think rolling back will help.

 

I guess the best course of action is to just leave it as-is in my controller.

 

Again, thanks for the help.