Salesforce Deployment with Java

Perhaps the most familiar deployment tool for SF admins/developers is the change set.
However for many of them, this is only method known for deployment. Some knows there are additional "advance" option (ant, eclipse, IDE, workbench, metadata API) but most are not really know how to use them.
In many cases, after getting familiar with other methods, admins/developers find it much more comfortable.

In some projects, where I was the only developer, I found it useful to deploy any changes directly from my local file system. After implementing the changes in my Developer sandbox, I import all the components into my local file system using IDE, then using java tool to zip the relevant changes and deploy the changes to QA sandbox. I added some simple options like saving the deployed ZIP file for deploying it later to other environments, or running validation only.
I'm adding here the code mostly because good way to learn how to use SF metadata api.

The usage of the tool is quite simple. First time you need to setup the property file in the app folder or you can setup the properties from the app menu Options -> Option.

ZIP_FILES_FOLDER - the folder where you want to store the zip files
TARGET_URL - should be either login/test (login for production)
PACAKGE_API - package API you want to user during deployment
LOCAL_FOLDER - folder where your local SF files are stored. This must be valid src folder, and the folder inside must match the folder names according to SF API. Note, that if you generated the folder using retrieve or by other tools that SF support (like Eclipse IDE) then the folder will be valid.
SF_USER - SF user name
DEPLOT_METHOD - should be either validate/deploy

After opening the app, click button 'Add Files' to select the components you want to deploy.

  • Click clear to remove the files you added
  • Click create package to save the ZIP file with the components you added
  • Click Load ZIP in case you want to use ZIP file that saved previously
  • Click Deploy ZIP to start deployment (you will need to enter your SF credential.











Technical side (code)
Of course I'm note going to go thru all the code, I'll just explain the main and important points. The rest you can review by yourself. Note, that you should have some background in Java or DotNet in order to understand it.
See full code + jar file for download at:
https://github.com/liron50/sf-local-deployment-tool

1. Main classes: I have the main class LocalDeploymentTool. This contains all the GUI - buttons, messages, menus etc... In this case, I added in this class also the actions for the buttons, although it can be good idea to separate them to different classes (view and controller).
However, you can see that each of the button have dedicated Action, and for most of the action, when it's require more than few lines of code, I moved the logic into class - DeploymentUtilities. In addition, constant and some other setup values are located in class - DeploymentParams.

2. Note, in the class DeploymentParams, there is setup regarding the different SF component types.
See map folder_SFType_Map. It hold per each type it SF API name and boolean indicating if this type contains meta-xml file in addition to the main file.
Also note that it doesn't contains all components types in SF. Other types, can be added, but there are some types in SF that require special logic.

3. When working with ZIP I'm using the ZipArchive library. For some cases I notice that when using library from java.util.zip I might get error during deployment.

4. I'm using 2 additional classes. First is InputDialog. It's actually stand alone class that can be used anywhere to get several user inputs. It is in used when I need to deploy and should setup the username/password/some other parameters.
Second class SyncWorker. It's only used to run the deploy process in background. Otherwise the app GUI will be locked during deployment.

5. The app uses several external jar files. 2 of them are generated from SF wsdl (partner.jar, metadata.jar), if you need to create them please refer to SF documentation.

6. The deployment logic is based on SF example. See documentation + example:
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy.htm
















No comments:

Post a Comment

Retire of Permission on Profiles

If you are working as a Salesforce admin/developer you've probably heard somewhere that Salesforce is planning to make a significant cha...