Post Salesforce Data to Non-Salesforce Forms

I had a requirement to look up some information related to a customer in another system. The other system had a simple form where you would enter the data you wanted to lookup and it would give you the details from the other system. I needed a button on the record in Salesforce that when clicked would post the data to the external form and show me the results. I found this great solution on StackExchange and modified it to fit my needs.

First I needed a detail button that executes JavaScript:Crerating Custom Button

The JavaScript would look something like below. It consists of a function which does the post to the form. I then do a simple call to the function, passing in the endpoint plus all the IDs of the form elements that need to be filled and their values. In this case, I’m looking for two phone numbers and passing in the account’s phone and fax numbers

function post_to_url(path, params, method) {
method = method || "post"; // Set method to post by default, if not specified.

var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
form.setAttribute("target", "_blank");

for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);



phone2: "{!Account.Fax}"});

One caution when using this technique: if the target form ever changes, you’ll need to modify the JavaScript to match.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s