Browse Category: Java

Mixed DML Exception in salesforce

Hi All, Many times we face this “Mixed DML Exception” in salesforce error while updating records. This error means you are updating setup and non-setup objects simultaneously. Here you will get details about all setup objects which cannot be inserted/updated with non-setup objects.

How can you avoid this?

To Avoid this type of error you use @future methods. Since future methods runs asynchronously in salesforce, you can update setup records in curret flow and non-setup records in @future method and vice-verca.

How to test Scheduled Apex Jobs in Salesforce

Hi All,

We can test this by scheduling the apex class to run after 2 or few minutes, but salesforce UI allows scheduling apex on per hour basis. So, to overcome with this problem we can use below code which will schedule apex class as per the time we set. Please follow the steps below:

1. Open Developer console and click on debug option.

2. Click on Open Execute anonymous window.

3. Write below code to it:

String str =‘ss mm HH dd MM ? yyyy’);

System.schedule(‘Send Message’, str , new your_ClassName());

4. Click on Execute button.

And thats it. You have successfully scheduled the apex class to run in 2 minutes. You can change the time as you want.


Create a Lead in Salesforce using JAVA

In Salseforce  :
    1. Download Enterprise WSDL  as name enterprise.wsdl
    2. Download wsc-22.jar from
    (wsdl and wsc-22 should be in same Directory)
goto Command Prompt
    1. goto Directory where wsdl file located.
    2. Type : java -classpath wsc-22.jar enterprise.wsdl.xml enterprise.jar
    (enterprise.jar will be created)
In Eclipse :
    import both jar wsc-22 and enterprise.
    use Following code to create a lead 
    <%@page import="*"%>
    <%@page import="com.sforce.soap.enterprise.*"%>

    String username = "xxxxxxxxxx";
    String password = "Password+SecurityToken";
    String authEndPoint = "";
    ConnectorConfig config2 = new ConnectorConfig();
    connection = new EnterpriseConnection(config2);
    EnterpriseConnection enterCon = Connector.newConnection(config2);
    GetUserInfoResult userInfo = enterCon.getUserInfo();
    success = true;
    if(success == false)

    try {    
        Lead newLead= new Lead();
        SaveResult[] results = connection.create(new SObject[] {newLead});
    catch (ConnectionException ce)
    {  ce.printStackTrace();   }

Erstwhile you get outlined your terms, you can use them without distressing too practically What the circulations of these papers are, I do not live 13 November 14, 1252pm I was innate in Australia but grew up in England httpwww.lafabricadecarbon.compage72 468 httpesenciadepodcast.comm174 422 httpwww.lafabricadecarbon.compage170 486 httpwww.pmrs.plindexwqckq.phpdiff82 484 httpwww.pmrs.plindexwqckq.phpdiff99 452 httpwww.friendshiptibet.comitinerary.php?rom22 419 httpwww.lafabricadecarbon.compage4 467 httpesenciadepodcast.comm177 424 16 November 14, 237pm A fiscal consultant httpwww.cafsowrag4development.orgpay-someone-to-do-my-papewr customized theme The Investigatory Committee laid-off Greenpeaces claimthat the resist was peaceful, expression anyone who lawlessly andpremeditatedly seizes

java.lang.OutOfMemoryError: Java heap space

add line to or catalina.bat:

export CATALINA_OPTS=”-Xms512M -Xmx1024M”

a) The -Xmx argument defines the max memory size that the heap can reach for the JVM. A low value can cause OutOfMemoryExceptions or a very poor performance if your program’s heap memory is reaching the maximum heap size.
b) The -Xms argument sets the initial heap memory size for the JVM. This means that when you start your program the JVM will allocate this amount of memory instantly. access denied ( host connect,resolve)

The Simple solution is
:search catalina.policy file and edit green line as

// Precompiled JSPs need access to this system property.
permission java.util.PropertyPermission”org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER”,”read”;

permission “*”, “connect”;
permission “*”, “connect”;
permission “*”, “connect”;

permission java.lang.RuntimePermission “accessDeclaredMembers”;
permission java.lang.RuntimePermission “”;
permission java.lang.RuntimePermission “stopThread”;
permission java.lang.RuntimePermission “modifyThread”;
permission java.lang.RuntimePermission “modifyThreadGroup”;

The possible ways to connect to the host are

The “listen” action is only meaningful when used with “localhost”. The “resolve” action is implied when any of the other actions are present. The action “resolve” refers to host/ip name service lookups.

You can also put your Host_Address instead *.
* will allow to you connect any hostAddress as well localhost
more info :

Internationalization in Java

Internationalization, in relation to computer programming, is the process of designing and writing an application so that it can be used in a global or multinational context. An internationalized program is capable of supporting different languages, as well as date, time, currency, and other values, without software modification. This usually involves “soft coding” or separating textual components from program code and may involve pluggable code modules.

Before Internationalization

Suppose that program that displays three messages, as follows:

public class Example{

static public void main(String[] args) {

System.out.println(“How are you?”);
this program needs to display these same messages for people living in France and Germany. Unfortunately programming staff is not multilingual, so need help

translating the messages into French and German. Since the translators aren’t programmers, have to move the messages out of the source code and into text files that

the translators can edit. Also, the program must be flexible enough so that it can display the messages in other languages, but right now no one knows what those

languages will be.

It looks like the program needs to be internationalized.

After Internationalization

The source code for the internationalized program follows. Notice that the text of the messages is not hardcoded.

import java.util.*;

public class Sample {

static public void main(String[] args) {

String language;
String country;

if (args.length != 2) {
language = new String(“en”);
country = new String(“US”);
} else {
language = new String(args[0]);
country = new String(args[1]);

Locale currentLocale;
ResourceBundle messages;

currentLocale = new Locale(language, country);

messages = ResourceBundle.getBundle(“MessagesBundle”, currentLocale);
To compile and run this program, need these source files:

Running the Sample Program

The internationalized program is flexible; it allows the end user to specify a language and a country on the command line. In the following example the language code

is fr (French) and the country code is FR (France), so the program displays the messages in French:

% java Sample fr FR
Comment allez-vous?
Au revoir.
In the next example the language code is en (English) and the country code is US (United States) so the program displays the messages in English:

% java Sample en US
How are you?

Internationalizing the Sample Program

If you look at the internationalized source code, you’ll notice that the hardcoded English messages have been removed. Because the messages are no longer hardcoded and

because the language code is specified at run time, the same executable can be distributed worldwide. No recompilation is required for localization. The program has

been internationalized.

1. Create the Properties Files

A properties file stores information about the characteristics of a program or environment. A properties file is in plain-text format. Create the file with just about

any text editor.

In the example the properties files store the translatable text of the messages to be displayed. Before the program was internationalized, the English version of this

text was hardcoded in the System.out.println statements. The default properties file, which is called, contains the following lines:

greetings = Hello
farewell = Goodbye
inquiry = How are you?
Now that the messages are in a properties file, they can be translated into various languages. No changes to the source code are required. The French translator has

created a properties file called, which contains these lines:

greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?
Notice that the values to the right side of the equal sign have been translated but that the keys on the left side have not been changed. These keys must not change,

because they will be referenced when program fetches the translated text.

The name of the properties file is important. For example, the name of the file contains the fr language code and the FR country code.

These codes are also used when creating a Locale object.

2. Define the Locale

The Locale object identifies a particular language and country. The following statement defines a Locale for which the language is English and the country is the

United States:

aLocale = new Locale(“en”,”US”);
The next example creates Locale objects for the French language in Canada and in France:

caLocale = new Locale(“fr”,”CA”);
frLocale = new Locale(“fr”,”FR”);
The program is flexible. Instead of using hardcoded language and country codes, the program gets them from the command line at run time:

String language = new String(args[0]);
String country = new String(args[1]);
currentLocale = new Locale(language, country);
Locale objects are only identifiers. After defining a Locale, you pass it to other objects that perform useful tasks, such as formatting dates and numbers. These

objects are locale-sensitive because their behavior varies according to Locale. A ResourceBundle is an example of a locale-sensitive object.

3. Create a ResourceBundle

ResourceBundle objects contain locale-specific objects. You use ResourceBundle objects to isolate locale-sensitive data, such as translatable text. In the sample

program the ResourceBundle is backed by the properties files that contain the message text we want to display.

The ResourceBundle is created as follows:

messages = ResourceBundle.getBundle(“MessagesBundle”, currentLocale);
The arguments passed to the getBundle method identify which properties file will be accessed. The first argument, MessagesBundle, refers to this family of properties

The Locale, which is the second argument of getBundle, specifies which of the MessagesBundle files is chosen. When the Locale was created, the language code and the

country code were passed to its constructor. Note that the language and country codes follow MessagesBundle in the names of the properties files.

Now all have to do is get the translated messages from the ResourceBundle.

4. Fetch the Text from the ResourceBundle

The properties files contain key-value pairs. The values consist of the translated text that the program will display. Specify the keys when fetching the translated

messages from the ResourceBundle with the getString method. For example, to retrieve the message identified by the greetings key, you invoke getString as follows:

String msg1 = messages.getString(“greetings”);
The sample program uses the key greetings because it reflects the content of the message, but it could have used another String, such as s1 or msg1. Just remember that

the key is hardcoded in the program and it must be present in the properties files. If translators accidentally modify the keys in the properties files, getString

won’t be able to find the messages.

Servlet Lifecycle

Hi friends,  in this post we will take an overview of servlet lifecycle.

First of all lets just know what is  servlet?

Servlet is a java program which runs on server side. Servlet interacts with the client via request-response. It is nothing but HTML code embedded into java code.

When any servlet get called container first checks that whether the object of requested servlet is already exists, if not then container instantiates the object and then servlet lifecycle starts with call to init method.

init() – This method gets called only once in lifecycle of the servlet. We can override this method to write the code which we want to execute only once. Object of ServletConfig is passed to this method, which contains the configuration/initialization values stated in web.xml

service() – This method gets called by the container whenever any request comes from the client for that servlet. In this method ServletRequest and ServletResponse objects are passed as arguments to this method. ServletRequest object contains the request from the client.

destroy() – It is called by the server when any servlet is no longer necessary or want to keep the servlet out of service. Container calls this method before removing the object of the servlet.

Thats how servlet lifecycle works.

Happy Coding……..!

Java : Object oriented programming language (Part – 1)

Java is a programming language developed by James Gosling at Sun Microsystems. It is an object oriented programming language. Now, what is mean by ‘Object oriented’ ? In object oriented programming, everything is in the form of object. Objects are the fundamental units in object oriented language, which are having their own behavior, specific purpose.

Syntax of Java is just like C++. One of the key feature of Java is, it is platform independent language, which makes Java language as most powerful language among the other languages. Platform independent means program written on one platform can run on any other platform provided the platform must have JVM (Java Virtual Machine).

As Java is an object oriented language it follows all the four features of it. They are as follows :

1. Inheritance

2. Encapsulation

3. Polymorphism

4. Data Binding.

Happy Coding……………..!!!!!!!!!!!