Search code examples
modulesalesforceapex-code

Can one implement Apex libraries or modules to import in force.com projects?


One can develop projects using force.com. However, is it possible develop apex code libraries and import them in a project, a bit like dependencies in maven and java? If yes, how should one proceed? I am exploring the framework. Thanks.


Solution

  • Apex doesn't really have concept of Java-like packages & dependencies. Most of your custom classes sit in one big namespace which sometimes leads to very long class names. For more info you might want to check out the Disadvantages of the Force.com platform

    Having said that you can make something that's called "package" in the documentation. But think about it like a plugin to your Force.com solution as a whole. You could create a package that contains only some code libraries but it's much more common to build ones that come with their own objects, visualforce pages, reports etc. Essentially all you see on http://appexchange.com/ are such packages... This is probably a terrible analogy but I'd compare them to WAR files, not JARs.

    Package can be managed (meaning the party that developed it controls it, you can't see their source code but you can use methods exposed with global keyword for example). Unmanaged packages exist too - you're free to modify them as you see fit, delete things you don't need. Chatter Unfollow Rules is an example of unmanaged package. Another one (let's you install as well as browse code before diving deep into the installation) could be http://code.google.com/p/apex-lang/

    To make stuff more complicated you can make private packages too ;) You could then deploy it into your different salesforce orgs without publishing on AppExchange.


    If this seems to be too chunky and what you're after is dependency control, deploying of project as a whole etc - perhaps you should read about "changesets" or even "Force.com Migration Toolkit" (which should be really easy to use for you if you know Ant).

    At the very least I hope I gave you several new keywords to Google for now ;) You might also want to ask same or more detailed question on salesforce.stackexchange.com - there are several pretty hardcore integrators and app developers there who might provide you with better answers.