Use a List button to POST data to an external page

This is actually more of a lesson in JavaScript, but it shows how flexible the Salesforce environment can be to meet various requirements. The ability to add “OnClick JavaScript” behind a button is a really nice feature.

My requirements were:

  1. Ability for an end user to, from an Account view, check the records that need to be processed and click a button to process them.
  2. The processing is to take place in an external PHP page
  3. Pass the parameters as an HTTP POST transaction (i.e. do NOT include the parameters in the URL string).

I knew I would need to create a custom List button so that it could appear above the view. I used the OnClick JavaScript option because what I needed to do was simple and I didn’t want the overhead of an s-Control getting invoked. That solves requirement #1.


Requirement #2 could be solved by having the button use 2 lines of JavaScript to pass the parameters to the PHP page.

idArray = {!GETRECORDIDS($ObjectType.Account)};“{!API.Session_ID}

This got the job done, but violates requirement #3, which is to keep the data sent to the page hidden from view.

To meet requirement #3, I had to use JavaScript to dynamically build an HTML form on the fly, add data to it and then submit it.

// create the form. Set it up to POST the transaction
f = document.createElement(“form”);
f.method = “post”; = “_blank”;

// add the session id as a parameter
i = document.createElement(“input”); = “session”; = “session”;
i.type = “hidden”;
i.value = “{!API.Session_ID}”;

// add the server location as a parameter
i = document.createElement(“input”); = “server”; = “server”;
i.type = “hidden”;
i.value = “{!API.Partner_Server_URL_90}”;

// Get the Account IDs that were checked
idArray = {!GETRECORDIDS($ObjectType.Account)};

// add the idArray as a parameter
i = document.createElement(“input”); = “idArray”; = “idArray”;
i.type = “hidden”;
i.value = idArray;

// add the form to the document.

// submit the form

This solution worked perfectly. The end result was that the PHP page the form posted to was able to retrieve the Salesforce session Id, endpoint location and an array of Id values via the $_POST variable and none of those parameters were visible in the URL. The PHP was opened in a new window, which was defined in the = “_blank”; line above.

I don’t know if there’s an easier way to do this or not (comments are welcome), but this turned out to be very easy and is an approach I will re-use. The hardest part was trying to figure out the JavaScript syntax.

This is a nice trick for non-Salesforce JavaScript development too.


  1. Steve Said,

    May 2, 2007 @ 9:12 pm

    Cool tip. I could see using this in a simple integration I’m dealing with between and another web-based system. Thanks!

  2. Hari Said,

    August 19, 2009 @ 6:50 am

    This was useful in our project trying to implement login of a user without the prompt functionality to an external system.. Thanks Scott!

RSS feed for comments on this post