Naming a class in Salesforce the same as a built in interface

I am currently working on a small managed package for a Salesforce project. One of the nice things you can do inside of managed packages is create post-install scripts, which are sort of like migrations in Rails.

For some reason, I kept getting a compiler error when I created even the simples of install handlers:

global class PostInstallHandler implements InstallHandler {
	global void onInstall(InstallContext context) {	}

The error I got back was "Compile Error: PostInstallHandler: Invalid interface: InstallHandler at line 1 column 44"

Well, InstallHandler is a built-in interface. Why would it give this error? I tried creating the same class in a different Salesforce organization, and it compiled just fine.

It turns out, someone (probably me) created a CLASS called "InstallHandler" from inside the Salesforce web application. It wasn't automatically showing up in my development tool (MavensMate), because I hadn't re-synced the project. After doing a sync, I noticed the class, deleted it, and all was well.

This brings up some interesting observations:

  1. Salesforce will happily let you create a class with the same name as a built-in interface, at least if you are in an organization that is tied to the development of a managed package.
  2. "Invalid interface" means "This Interface you are asking for exists, but it's not an interface". When I read the error the first time, it seemed like the interface did not exist, but the actual error message for an interface not being found is "Invalid type: InstallHandlerDoesNotExist"

Leave a Reply