Performing Load Testing in Salesforce using Selenium and TestNG

Selenium Salesforce load Testing

When we build any custom solution in Salesforce, key is to write an efficient and meaningful Apex test classes for sure. However sometime we may need to test how custom application would behave in maximum operating capacity. Here, I am talking about Load Testing of custom applications built on top of platform. Recently I needed to push my code to its limit to know how many concurrent users can use it before hitting any governor limits. Quickly I realize that its time to call my friends Selenium and TestNG.

Before doing any extensive stress or load testing on Salesforce, we must need to contact Salesforce support and explain them what we are trying to achieve. More detail available in this official Salesforce blog post.

I have published some blog posts about Selenium in past as well however whats different this time ? I need to determine after how many simultaneous user interactions, I would hit Concurrent Apex Limit error as shown in below image.

Salesforce Governor Limit error - Concurrent Apex Limit
Salesforce Governor Limit error – Concurrent Apex Limit

Creating custom ANT plugin or Task in Java

ANT is very powerful and one of the most used tool in Java and other platforms like Salesforce. In Salesforce, ANT is officially used to deploy changes on instances using Metadata API. It is also integral part of Continuous Integration. Even though, there are hundreds of libraries and ANT Tasks are available to use, however there are many scenarios where we need to create our own custom Task.

I am using many custom ANT tasks in my projects and its very easy to create. For example, I have created automated data load process with custom ANT task, which is almost as powerful as of any paid ETL tool.

In this blog post, We will go through creation of very simple ANT plugin. We will create a custom ANT Task with nested tags , attributes and then print it on console. It shows that, we can read attribute passed in build.xml. if we can read attribute, then writing any custom logic is not a big deal.

Categorized as JAVA Tagged

Generating Single Executable jar file with all dependencies and libraries using Netbeans and Eclipse

Generating Single Jar file with all dependencies in Eclipse is easy. We just need to follow below steps :

  1. Either from the context menu or from the menu bar’s File menu, select Export.
  2. Expand the Java node and select JAR file. Click Next.
  3. In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.
  4. Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source files and resources. (Note: Selected resources are exported in both cases.
  5. If there are other files or resources you want to include they must be in a an open project. Browse to their location via the directory tree on the left and ensure the file or resource is checked in the window on the right.
  6. In the Select the export destination field, either type or click Browse to select a location for the JAR file.
  7. Select or clear the Overwrite existing files without warning checkbox. If you clear this checkbox, then you will be prompted to confirm the replacement of each file that will be overwritten.
  8. Click Finish to create the JAR file immediately.
  9. Now, navigate to the location you specified for the jar. The icon you see and the behavior you get if you double click it will vary depending on how your computer is set up.
  10. You can use this article for images and more detail.

Create Excel File in Java using Apache POI Library

Recently, I came across requirement to create ExcelSheet from thin Java Client used by Salesforce. So, I though to share my experience on Creating Excel Sheet in Java. As we know that Java is product of Oracle and Excel is product of Microsoft. Off-course, There will be no standard functionality available in Java to achieve our requirement of creating Excel Sheet. However thanks to Apache for their POI Library. POI Stands for “Poor Obfuscation Implementation” as the file formats created by this library is obfuscated poorly with help of reverse Engineering. Anyways, we don’t have to bother about it and thankful to them for providing such wonderful library.

Apache POI library can be used to create Excel Sheet, Word Document and PowerPoint. In this post, we will be totally focusing on Excel Sheet using “XSSF (XML Spreadsheet Format)” component.

Prerequisite :
Add all jar files downloaded from Apache POI download site in Java Program’s build path.

Introduction to Hibernate

Post by – Subhash Bhajankar

What is the problem that hibernate is trying to solve?

         Let’s take an example of simple class that you have in your application. Referring Image 1, we have Employee object in our java class which has six fields. In our running application We would have lots of such objects in memory, What if I restart my application ? Everything will be lost. So to overcome this problem and persist data inside my application i will save it in Database.

         As shown in below image every object in Java will be represented as single row. Here, class corresponds to table and object of class corresponds to row. This was something that we were been doing over the year (Off course before ORM Tool).

Normal approach to save data in Java is something like :

  1. Create JDBC Connection
  2. Connect Database
  3. Create SQL String dynamically by taking fields value one by one
  4. And also manage all transaction, Exception handling, rollback and commit
Categorized as Hibernate

Creating First Application in Heroku using Eclipse

Hello Readers, in this article we will see step by step procedure to deploy your first (Hello World) program in Heroku. There are two ways, first going through series of Commands of “Heroku” and “GIT” and other simple and smart way is to use Eclipse Capability with Heroku. To make things easier we will go by second method.


This tool / blog post is deprecated. Please follow this guide to deploying applications to Heroku from Eclipse. If you still want to follow this post, then download Eclipse plugin for Heroku from here.


Installation and Set up:
First we will need to Install Heroku Plugin in Eclipse. To install it, Navigate to “Help | Install New Software” and click on “Add” button.

Give any name in website like “Heroku Plugin” and enter this URL in Location and click on “Ok” and Finish Installation. It will install the Heroku Plugin required to start your first Plugin.

Next step is setting up your Credentials for Heroku :

Navigate to “Window | Preferences | Heroku”, Here either enter your UserName and Password of Heroku Account and click on “Login” or enter you API key, which you can find by logging into your Heroku Account.

Setting up Credentials for Heroku in Eclipse
Setting up Credentials for Heroku in Eclipse

Resolve Error “ArtifactTransferException: Could not transfer artifact” or “Failure to Transfer” in Maven

This is very short tips to resolve the errors “ArtifactTransferException: Could not transfer artifact” that may occur in Maven project in Eclipse.

Steps to resolve:

  1. Open folder by running this text (without Quotes) in Search Explorer of Window “%USERPROFILE%.m2”.
  2. After running above command, “m2” folder of maven will open. Now search for file (without Quotes) “*.lastUpdated”.
  3. In this step, delete all the files found by running Step 2.
  4. Now go to Eclipse project and select “Maven | Update Dependency” or “Maven | Update Project”.

By now, your issue will be resolved.

Happy Coding !!!

Merge PDF in Salesforce Using Java, ITextPDF and OAuth 2

Its long time, since i wrote any article because of my busy schedule However this time i came with advance one. In this article we are going to use the J2EE (Servlet) to Merge PDF attachment inside salesforce with the help of OAuth and ITextPDF jar file. The reason of writing this article is that there is no native support by Apex to merge two attachments in Salesforce. Either we have to go for AppExchange product like CongaMerg or Drawloop or we can write our own code in any other language like Java and C# and with the help of REST API we can save get and save attachment in Salesforce.

First we will need to setup the OAuth permission so that our local J2EE application can interact with Salesforce. For this login to Salesforce account and Navigate to “Set up | App Set up | Develop | Remote Access” and enter the information. Be careful about the “Callback URL”. It must match in your code. After creating the “Remote Access”, note “Consumer Key” and “Consumer Secret” which will be needed in your code.

Update : “Remote Access” is renamed to Connected App. So throughout this article, if you see image of “Remote Access” then please consider it as Connected App.

Create Remote Access in for OAuth 2
Create Remote Access in for OAuth 2

Simple guide to setup SSL in Tomcat

I have enabled SSL in tomcat many times however initially I struggled to get it in running condition. So I thought to share a simple approach I am following now days.

Step 1:

Run tool “Keytool“ provided by the JRE to create a “keystore file”.
The command to run tool is:

keytool -genkey -alias tomcat -keyalg RSA -keystore D:/.keyStore

Where “D:/.keystore” is the path where file should be created.
Instead of alias “tomcat” any other name can be used.
After running above command, you will be asked many questions, so answer them correctly as shown in below image:

Tomcat SSL keytool to create keystore file
Tomcat SSL keytool to create keystore file

Remember the password provided, as it will be needed in next step.

Method Parameters – Pass by Value or Pass by Reference

This topic has always been part of discussion where the answer is not satisfactory and convinced to others. Using this article, I will try to explain the concept of parameter passing in Apex Method. This Complete topic is applicable for Java or other programming languages as well.

Before moving ahead let’s have a summary on what is pass by value and pass by reference.

Pass by value means when a method is called, a second copy of the parameter variable is made in memory, and this copy is passed to the method as a parameter. This copy can be modified in the method, but the original variable in the caller is unchanged, and the changes to the copy are lost upon return.

Pass by reference means when a method is called, that actual variable is passed to the method.

Million dollar question: parameters in method are passed by value or pass by reference?
Most of answers: primitive data types like Integer, Double are pass by value and Objects are pass by reference.

However, the above statement is not 100% true. I know I just invited controversy on this post. Be Patient with me and I would prove with actual example, feel free to run these examples in your Developer Console.

Correct Answer: parameters are passed by value in Apex as well as in Java. Where, in case of object the copy of reference is first made and then passed, therefore we can change the fields of object inside method however we cannot change the Object itself.

Take a pause here and think what I just said. I’m saying, new variable copy created which points to same Object. So, it seems reference but variable technically itself is storing value which is address or reference of object.

Let’s discuss this in more detail. I am going to explain two scenarios in which I will try to change the field value and in second example I will try to change Object itself.

Example 1

Account a = new Account(); 
a.Name = 'Shivasoft'; 
a.Website = ''; 
System.debug('Website - '+a.Website); 

public void changeWebsite(Account b) { 
    b.Website = ''; 

Output of above code is

Website -

What just happened in Example 1

Salesforce Pass by Value or Pass by Reference - Scenario 1
Salesforce Pass by Value or Pass by Reference – Scenario 1

As per code snippet, the object a is supplied in method changeWebsite(). The parameter is actually passed by value, where the copy of value a is passed to object b which is memory address (aka reference). As we can see that both variable have reference of same object and hence whatever changes done by variable b on that object it will be applicable for variable a also.

If you are still not convinced and think I’m wrong, wait for example 2.

Example 2

Account a = new Account(); 
a.Name = 'Shivasoft'; 
a.Website = ''; 
System.debug('Website - '+a.Website); 

public void changeWebsite(Account b) { 
    //Create New Object and try to replace old 
    b = new Account();
    b.Website = ''; 

Before I go further and reveal answer, let’s think what would be output ?

If you assumed method parameters are passed by reference then output should be

Website -

However actual output is

Website -

What just happened in example 2 ?

Salesforce Pass by Value or Pass by Reference - Scenario 2
Salesforce Pass by Value or Pass by Reference – Scenario 2

As per code snippet, the object a is supplied in method changeWebsite(). Like I said, the parameter itself is actually passed by value, where the copy of value a is passed to object b which was reference. As we can see that both variable had reference of same object initially. However, inside the method new object is created and reference assigned to b and just now important event occurred. Refer above image for clear explanation

Previously b was pointing to old object, if it was really reference then it should impact object a. However now a and b variables point to different object. Whatever the changes done inside method, it will not be reflected outside as object a still have old reference. And hence after method execution when we check the value of object a, it is not affected because of method execution.

Salesforce documentation says :

“In Apex, all primitive data type arguments, such as Integer or String, are passed into methods by value. This means that any changes to the arguments exist only within the scope of the method. When the method returns, the changes to the arguments are lost.
Non-primitive data type arguments, such as sObjects, are also passed into methods by value. This means that when the method returns, the passed-in argument still references the same object as before the method call, and can’t be changed to point to another object. However, the values of the object’s fields can be changed in the method.”

Time for Best Practice

Because of behavior of parameters are passed as a value, it is always best practice to return object back to calling method. JUST DON’T ASSUME that object is passed by reference and whatever happened inside method will reflect calling method.

So code would become

Account a = new Account(); 
a.Name = 'Shivasoft'; 
a.Website = ''; 
a = changeWebsite(a); 
System.debug('Website - '+a.Website); 

public Account changeWebsite(Account b) { 
    //Create New Object and try to replace old 
    b = new Account();
    b.Website = ''; 
    return b ;