Ye Meri Life Hai - Chirag Mehta

Be Good & Do Good!

Month: December 2009 (page 1 of 2)

Increasing Java Heap for Ant

I ran across a little tip tonight I thought I should share. Trying to perform a large Salesforce Code migration with Ant kept giving me the following error: Out of memory. Increase Heap Size.

This is a Java error indicating that the virtual machine is out of memory. So now I know what the problem is, what next? If I was launching from a command line changing the heap size is not that tough. Just look up the options for java and set a new value, but I’m using Ant. Looking at the Ant shell script or batch file was no help.

Well a bit of Googling turned up that Ant looks for an environment variable called ANT_OPTS which is use to set Java parameters. Just set the environment variable and off you go. So I added the following to increase the heap size:

export ANT_OPTS=-Xmx256m

That sets the maximum heap size to 256 Megabytes. So if you ever need to increase the size of the Ant JVM, now you know how.

Apex Code to Invoke an External Web Service

To invoke an external service after using its WSDL document to generate an Apex class, create an instance of the stub in your Apex script and call the methods on it.

For example, to invoke the StrikeIron IP address lookup service from Apex, you could write a script similar to the following:

// Create the stub
strikeironIplookup.DNSSoap dns = new strikeironIplookup.DNSSoap();

// Set up the license header
dns.LicenseInfo = new strikeiron.LicenseInfo();
dns.LicenseInfo.RegisteredUser = new strikeiron.RegisteredUser();
dns.LicenseInfo.RegisteredUser.UserID = ‘you@company.com’;
dns.LicenseInfo.RegisteredUser.Password = ‘your-password’;

// Make the Web service call
strikeironIplookup.DNSInfo info = dns.DNSLookup(‘www.myname.com’);

Read More @ Salesforce.com

Web Service Callout Request/Response Size Governor Limit

The release of Summer 09 increased the governor limit of a SOAP web service callout request/response size to 1MB from 100KB as can be seen in the Apex documentation here

If you are using the Apex HTTP classes to send web service callouts, the limit is still 100KB. .

Salesforce Web service Callout Limits(Timeouts)

The following limits apply when an Apex script makes a callout to an HTTP request or a Web services call. The Web services call can be a Force.com Web Services API call or any external Web services call.

  1. A single Apex transaction can make a maximum of 10 callouts to an HTTP request or an API call.
  2. The default timeout is 10 seconds. A custom timeout can be defined for each callout. The minimum is 1 millisecond and the maximum is 60 seconds. See the following examples for how to set custom timeouts for Web Services or HTTP callouts.
  3. The maximum cumulative timeout for callouts by a single Apex transaction is 120 seconds. This time is additive across all callouts invoked by the Apex transaction.

The following is an example of setting a custom timeout for Web services callouts:

docSample.DocSamplePort stub = new docSample.DocSamplePort();
stub.timeout_x = 2000; // timeout in milliseconds

The following is an example of setting a custom timeout for HTTP callouts:

HttpRequest req = new HttpRequest();
req.setTimeout(2000); // timeout in milliseconds

How to Set Java Heap Space

The Java Virtual Machine (JVM) is the execution component of the Java Runtime Environment (JRE) that interprets and executes the byte code stores in a Java class. Within the Java Virtual Machine is a notional idea of the Java heap which is where objects created in a Java class reside in memory during the program’s execution.

When an object is done being used by the executing program, the Java Garbage Collector frees the memory in the Java Heap used by the object. If your java program requires an extensive use of memory and you do not increase the default Java Heap size, then your program can fail on a “out of memory” Java exception.

Step1 Open the command or DOS prompt on your computer. To open the prompt, select the “Start” menu and type “command” in the search text field followed by the “Enter” key.

Step 2 Change the DOS directory to the location of the Java program you are going to execute with the larger Java Heap size. To do this, type “cd ” followed by the fully qualified directory path of the class files. An example of this is: “cd c:\myjavafiles”.

Step 3 Change the max Java Heap size to 128 megabytes through the use of command line arguments on the Java Virtual Machine invocation. To do this, type the following command at the DOS prompt followed by the “Enter” key:
java –Xmx128m YourClassNameHere

Step 4 Exit the Java program run in Step 3. Re-run the Java application setting an initial default Java Heap size of 32 megabytes (MB) with the ability to increase the heap size to 128 MB if required by typing the following command at the DOS prompt followed by the “Enter” key:

java -Xms32m -Xmx128m YourClassNameHere

Salesforce Java Application to export Attachments – Appreciation …

Following are few appreciation notes from client, manager and team member ….

Ajay Kumar – Chirag chipped in early to find more details about this and got a fix in couple of long working days!! I would like to take this opportunity to appreciate Chirag’s terrific contribution and dedication on this. Bravo Chirag!! 🙂 U ROCK!!

Sue Gausch – I have already sung Chirag’s praises on this one, and will definitely continue to do so

Ajay Kumar – Chirag has been terrific in deliveries through past 6 months with wonderful client feedback. He has been instrumental in making a brand name for TATA’s.

Sunil Chauhan – Last few months have been nothing but great as far as your work is concerned. I have heard many good things about you in Dreamforce and now in Staples. I would love to imbibe your attitude and work ethic in the newbies who join our group. Keep up the good work and thanks for all your hardwork.

Salesforce – Move Attachments from 1 Organization to another

If you want to migrate from one org to another, then you first need to get a Weekly Export Service download. Make sure you check the “Include attachments” box. You will get an attachments.csv and the actual attachments.

The key to importing attachments is a little known feature inside Data Loader. The part that is not documented is that the import wants the actual filename in the BODY field. So for example, the attachments themselves have a ID name, let’s say its 123456789 and it is on your hard drive in the C:\Export folder. So in the BODY field you need to put C:\Export\123456789.

The only fields you need in the import file are – ParentId, Name, IsPrivate, OwnerId and Body.

5 ways Google Mail makes life easier

Many things are designed to make our lives easier, but sometimes they seem to make them more complicated. If everything worked like Google Mail, life would be much simpler!

Google launched set of 5 videos which illustrates how life is easier with Google Mail …

Google Mail conversation chains – Email replies are grouped into conversations with the original message
Offline Google Mail – You can access your email even when you are not connected to the internet
Google Mail spam protection – Spam-fighting technology saves you time
Google Mail themes – Customise your inbox with themes to suit your mood
Google Mail voice and video chat – Chat face-to-face with friends using built-in video chat

Watch the videos at http://google.co.uk/googlemailvideos

Salesforce – Stop Recursion of Trigger Execution

Suppose there’s a scenario where in one trigger perform update operation, which results in invocation of second trigger and the update operation in second trigger acts as triggering criteria for trigger one. In that case there will be a recursion and than will be Apex Governor Limits Errors .. bla .. ala .. bla ….

Following are two articles which helps to control or regulate the execution of multiple triggers and prevent recursion.

http://www.tehnrd.com/apex-flow-control-preventing-infinite-loops/

http://blog.jeffdouglas.com/2009/10/02/preventing-recursive-future-method-calls-in-salesforce/

Salesforce – Retrieve server URL in APEX class or trigger

In Visualforce controllers, use ApexPages.currentPage().getHeaders().get(‘Host’) to get the server name (e.g., na1.salesforce.com).

Older posts