Thursday, January 31, 2013

Getting INVALID_SESSION_ID using Salesforce's SOAP based API

For those of you consuming Salesforce SOAP API.

The more calls you make, the more errors you'll get (if you're using the same user to perform this calls)

This is a brief description of what happened to me:
I implemented a process to perform Realtime user provisioning by using Salesforce SOAP based API calls. In a few words this is my process:
  1. Login
  2. Generate User Account (Using Connection.upsert)
  3. Verify if User already exists (query User) to determine if next step will be Update or Insert
  4. Upsert (Insert or Update) User
  5. Upsert (Using Connection.upsert) other related objects (custom)
  6. Logout

This process gets invoked when performing SSO, therefore I get as many executions of this process as users try to access my portal.

There is no pattern on this issue.

This is the error I see in my PingFederate logs: [UnexpectedErrorFault [ApiFault exceptionCode='INVALID_SESSION_ID' exceptionMessage='Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key' ...

After login is been performed (could be before executing any step before Logout or during Logout) This error is generating incomplete user/accounts in Salesforce (Some objects are not created due to this error)


After a few calls and emails with salesforce Developer Support, I got a clear and simple answer:

"There is no implication by calling only login and no logout()"
"Client applications do not need to explicitly log out to end a session. Sessions expire automatically after a predetermined length of inactivity".

Then, instead of over-thingking this problem and design some complex solutions, just like: Implementing a connection pooling mechanism or making singleton my Connection object. The answer was easier than I thought. Don't call Logout and Login as many times as you need. You'll get the same Session_Id (your session will be refreshed on Salesforce and will remain active), letting Salesforce kill it when I'm not using it.

Cool!

Friday, January 4, 2013

How to recursively remove .DS_Store files on Mac OS X

The following command will remove all .DS_Store files in a directory where it is executed as well as that particular directory’s subdirectories:
find . -name '*.DS_Store' -type f -delete

Why would you want to remove .DS_Store files? The .DS_Store files store Finder-specific preferences concerning the display of each of your folders. Removing these files is an easy way to reset your display preferences. Also, if you’re moving files between your Mac and another operating system such as Windows or Linux these files can cause unexpected problems and should be removed prior to transfer.
This command works on Mac OS X (both 10.4 Tiger and 10.5 Leopard) and Unix-type operating systems such as Linux. What follows is a step-by-step guide on how to properly use this command on Mac OS X.

Directions on how to recursively remove .DS_Store files on Mac OS X
  1. Open up the Terminal application (/Applications/Utilities/Terminal.app).
  2. Find the directory/folder that you wish to recursively delete the .DS_Store files from. For this tutorial let’s pretend you want to delete all the .DS_Store files in your Pictures folder and every folder inside that folder. Type this command into Terminal (without pressing the return key):
    cd
  3. Then drag and drop your Pictures folder onto the Terminal window. The cd command should now look something like this–where ariadoss is your Mac’s “short name” (i.e. your username):
     cd /Users/jcruz/Pictures
  4. Press the return/enter key on your keyboard.
  5. Type the following command into Terminal and press return to execute it:
    find . -name '*.DS_Store' -type f -delete

Congratulations the .DS_Store files have been deleted! Please note that this command will just delete existing .DS_Store files; your Mac will continue to create them

If you wish to disable the creation of .DS_Store files on external volumes type the following command into Terminal and hit enter (you may need to logout or restart your computer after executing this command):
defaults write com.apple.desktopservices DSDontWriteNetworkStores true