You need to sign in to do that
Don't have an account?

How can I send data from Salesforce to an external system?
Hi there,
How can I send the data from Sales force to an external system?
I believe it can be done through a S-Control which can be attached to the custom button (URL type) that will trigger to send the data using HTTP POST method.
Has anyone ever done anything like this and could you share the details with me.?
Thanks
How can I send the data from Sales force to an external system?
I believe it can be done through a S-Control which can be attached to the custom button (URL type) that will trigger to send the data using HTTP POST method.
Has anyone ever done anything like this and could you share the details with me.?
Thanks
You can use that in a button or link on the object, or you can replace the first line with a normal script include for an S-Control. I do hope you find this useful.
I will try this right now and post my replies again here.
Thanks a lot
For testing purposes, I have set up IIS - locahost server. Therefore I would like to see the data displayed on the web page on my localhost.
So, I am assuming that I would have to set up the IIS - localhost webserver through salesforce first. Correct?
Also, in the code you mentioned earlier, where will I define the web page address:- Like this:-
postParams.url = 'http://localhost/SFO/DisplayFields.html'
thanks
=======================================================================
<html>
<head>
<script src="/soap/ajax/9.0/connection.js" type="text/javascript"></script>
<script>
function setupPage()
{
//function contains all code to execute after page is rendered
var state =
{
//state that you need when the callback is called
output : document.getElementById("output"),
startTime : new Date().getTime()
};
var callback =
{
//call layoutResult if the request is successful
onSuccess: layoutResults,
//call queryFailed if the api request fails
onFailure: queryFailed,
source: state
};
alert("start");
sforce.connection.query
(
"Select o.AccountId, o.Account.BillingCity, o.Account.BillingCountry, o.Account.BillingPostalCode, o.Account.BillingState, o.Account.BillingStreet, o.Account.Fax, o.Account.Id, o.Account.Name, o.Account.Phone, o.Account.Website, o.Id, o.Name, o.OwnerId, o.Owner.Name from Opportunity o where o.Id = '{!Opportunity.Id}' ",callback);
alert("end query");
}
function queryFailed(error, source)
{
alert("QueryFailed...");
source.output.innerHTML = "An error has occurred - query: " + error;
}
function layoutResults(queryResult, source)
{
var output = ""; // this variable will store the data and display the results using HTTP POST method.
if (queryResult.size > 0)
{
//get the records array
var records = queryResult.getArray('records');
//loop through the records and construct html string
for (var i = 0; i < records.length; i++)
{
var Opportunity= records[i];
// Using HTTP POST method to send data.
output.url = "http://localhost:8080/suma/",
output.method = 'POST',
output.requestData += "Opportunity Account ID=" + Opportunity.AccountId + "," +
"Opportunity Name=" + Opportunity.Name + "," +
"Opportunity ID=" + Opportunity.Id + "," +
"Account Billing City=" + Opportunity.Account.BillingCity + "," +
"Account Billing Country=" + Opportunity.Account.BillingCountry+ "," +
"Account Billing Postal Code=" + Opportunity.Account.BillingPostalCode+ "," +
"Account Billing State=" + Opportunity.Account.BillingState + "," +
"Account Billing Street=" + Opportunity.Account.BillingStreet + "," +
"Account Fax=" + Opportunity.Account.Fax + "," +
"Account ID=" + Opportunity.Account.Id + "," +
"Account Name=" + Opportunity.Account.Name + "," +
"Account Phone=" + Opportunity.Account.Phone + "," +
"Account Website=" + Opportunity.Account.Website + "," +
"Opportunity Owner ID=" + Opportunity.OwnerId + "," +
"Opportunity Owner Name=" + Opportunity.Owner.Name;
output.requestHeaders = {};
output.requestHeaders ['Content-Type'] = 'text/plain',
output.requestHeaders['Content-length'] = "postParams.output.length",
output.onSuccess = function (response)
{
sforce.debug.log(response);
},
output.onError = function (response)
{
alert("The code failed" + response)
},
sforce.connection.remotefunction(output);
} // this is the closing for FOR loop
} // this is the closing bracket for IF loop for records array.
//render the generated html string
// Comment this out if you are sending data from Salesforce to localhost.
//source.output.innerHTML = output;
} // this is closing bracket for FUNCTION where you have defined OUTPUT as the variable.
</script>
</head>
<body onload="setupPage()">
<div id="output"> </div>
</body>
</html>
=======================================================================
========================================================================
An error has occurred - query: TypeError: output.requestHeaders has no properties
========================================================================
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<html>
<head>
<script src="/soap/ajax/9.0/connection.js" type="text/javascript"></script>
<script>
function setupPage()
{
//function contains all code to execute after page is rendered
var state =
{
//state that you need when the callback is called
output : document.getElementById("output"),
startTime : new Date().getTime()
};
var callback =
{
//call layoutResult if the request is successful
onSuccess: layoutResults,
//call queryFailed if the api request fails
onFailure: queryFailed,
source: state
};
alert("start");
sforce.connection.query
(
"Select o.AccountId, o.Account.BillingCity, o.Account.BillingCountry, o.Account.BillingPostalCode, o.Account.BillingState, o.Account.BillingStreet, o.Account.Fax, o.Account.Id, o.Account.Name, o.Account.Phone, o.Account.Website, o.Id, o.Name, o.OwnerId, o.Owner.Name from Opportunity o where o.Id = '{!Opportunity.Id}' ",callback);
alert("end query");
}
function queryFailed(error, source)
{
alert("QueryFailed...");
source.output.innerHTML = "An error has occurred - query: " + error;
}
function layoutResults(queryResult, source)
{
var output = ""; // this variable will store the data and display the results using HTTP POST method.
if (queryResult.size > 0)
{
//get the records array
var records = queryResult.getArray('records');
//loop through the records and construct html string
for (var i = 0; i < records.length; i++)
{
var Opportunity= records[i];
output.requestData += "Opportunity Account ID=" + Opportunity.AccountId + "," +
"Opportunity Name=" + Opportunity.Name + "," +
"Opportunity ID=" + Opportunity.Id + "," +
"Account Billing City=" + Opportunity.Account.BillingCity + "," +
"Account Billing Country=" + Opportunity.Account.BillingCountry+ "," +
"Account Billing Postal Code=" + Opportunity.Account.BillingPostalCode+ "," +
"Account Billing State=" + Opportunity.Account.BillingState + "," +
"Account Billing Street=" + Opportunity.Account.BillingStreet + "," +
"Account Fax=" + Opportunity.Account.Fax + "," +
"Account ID=" + Opportunity.Account.Id + "," +
"Account Name=" + Opportunity.Account.Name + "," +
"Account Phone=" + Opportunity.Account.Phone + "," +
"Account Website=" + Opportunity.Account.Website + "," +
"Opportunity Owner ID=" + Opportunity.OwnerId + "," +
"Opportunity Owner Name=" + Opportunity.Owner.Name;
// Using HTTP POST method to send data starts here
sforce.connection.remoteFunction({
url : "http://www.cheenath.com",
onSuccess : function(response) {
alert("Got response" + response);
},
onFailure : function(error) {
alert("ERROR: " + error);
},
async: false
});
} // this is the closing for FOR loop
} // this is the closing bracket for IF loop for records array.
//render the generated html string
// Comment this out if you are sending data from Salesforce to localhost.
//source.output.innerHTML = output;
} // this is closing bracket for FUNCTION where you have defined OUTPUT as the variable.
</script>
</head>
<body onload="setupPage()">
<div id="output"> </div>
</body>
</html>
///////////////////////////////////////////////////////////////////////////////////
Note, the Salesforce will not be able to send data to IIS - Virtual Server, however to test the code I was able to send the data to an outside server. You can also try www.google.com or any other site that you can ping to.
Hope this helps and thanks for all your suggestions.
regards