Solved

Salesforce integration with External system using the HTTP POST method

Posted on 2007-11-21
26
3,950 Views
Last Modified: 2013-11-24
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
0
Comment
Question by:sumprit
  • 15
  • 8
  • 2
26 Comments
 

Author Comment

by:sumprit
Comment Utility
hi guys,

please respond , I am desperately looking for some answers here.

thanks
0
 
LVL 11

Accepted Solution

by:
techhealth earned 250 total points
Comment Utility
S-control is the hardest route to go.  :-)  Can you tell me a bit more about the task on hand?  SF has other easier ways for specific integration tasks.
1
 

Author Comment

by:sumprit
Comment Utility
So based on the requirements I have here are the details:-

1.> From Salesforce, under Opportunity user clicks on the Fulfillment custom button which will send out the details to an external system.

This custom button will capture the field details from the Opportunity and Account object. The following fields will have to be captured from the Opportunity object:-
      a) Opportunity ID
      b) Opportunity Owner
      c) Owner ID
The following fields will be captured from the Account object :-
      a) Account Name
      b) Account ID
      c) Billing Address
      d) Phone
      e) Fax
      f) Website
These details will be sent out to the external system called - BPM, using the HTTP POST method which can be accomplished through the S-Control embedded in a custom button.


0
 

Author Comment

by:sumprit
Comment Utility
the SOQL Query for the above is following:-

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 = '{!MERGE FIELD}

 
NOTE:-
-------
How the CRITERIA is designed, where Opportunity.ID = Opportunity.AccountID


0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
OK.  That does sound like something that requires a fair amount of manual coding...  So your BPM takes simple POST parameters instead of Web services calls?  That may or may not be a good thing.
0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
SF can do an outbound SOAP message via workflow triggers, which is much easier to set up than custom S-Control actions.
0
 

Author Comment

by:sumprit
Comment Utility
so what do you suggest is best approach to do this.

any example? any starting point to do this?
0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
Well, my question really is, how your BPM take in information?  Is it good old way like http://bpmsystem.com/input.cgi?para1=company&para2=name, or does it work like a Web services endpoint that takes a SOAP message for input?
0
 
LVL 22

Expert Comment

by:Bill-Hanson
Comment Utility
The easiest way is to pass minimal info to your remote server via URL parameters.

(1) Create a simple link that includes as parameters, the OpportunityId, the current SessionId, and the ServerUrl.
(2) In your server side code, use the Web Services API to validate the SessionId against the ServerURL, then do whatever you need to the Opportunity.
0
 

Author Comment

by:sumprit
Comment Utility
Thanks Guys!

I still have not received all the user requirements regarding this project. From the verbal discussion it seems, that a custom button will be placed on Oppurtunity tab and from there when the user clicks on this button, the field values will be sent over to the BPM System. I have not received the URL yet or on how this information will be received at the other end. I will find out by the end of the day.


0
 

Author Comment

by:sumprit
Comment Utility
As a starting point, I wrote this S-Control:-
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<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.Name,o.ID from Opportunity o WHERE o.id='{Opportunity.AccountID}' ",callback);

alert("end query");

}

function queryFailed(error, source)
{
alert("QueryFailed...");
source.output.innerHTML = "An error has occurred - query: " + error;
}

/**
* This method will be called when the toolkit receives a successful
* response from the server.
* @queryResult - result that server returned
* @source - state passed into the query method call.
*/
function layoutResults(queryResult, source)
{
var output = "";

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 += Opportunity.AccountId + " " + Opportunity.Name + " " + Opportunity.ID + " <br>";
}

}

// output += "ID - Status<br>";
//render the generated html string
source.output.innerHTML = output;
}
</script>
</head>

<body onload="setupPage()">
<div id="output"> </div>
</body>
</html>

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Here is what is happeneing here:-


1.> This S-Control is placed on the custom button called "Start the BPM" which is on Oppurtunity tab.
2.> Notice the SOQL Query, which is capturing the data from the fields.
3.> It will display the data in a seperate window.

4.> This is a starting point, and as I get more details this code will be edited.



0
 
LVL 22

Assisted Solution

by:Bill-Hanson
Bill-Hanson earned 250 total points
Comment Utility
This will get the data you need, but since you're just passing the data to another system, there is a much faster way.  Since you are just passing data from the current record, you don't need an sControl at all.  No SOQL either.  All you really need is a custom link that uses merge fields.

For example, to pass all of the fields you listed above to some external system, you can just create a URL to the external system like this:

https://your_server/your_agent?id={!Opportunity.Id}&aid={!Opportunity.AccountId}&oname={!Opportunity.Name}

Then the code on the receiving end can just extract the values from the query string.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 11

Expert Comment

by:techhealth
Comment Utility
That's why I asked what your BPM takes as input.

>>All you really need is a custom link that uses merge fields.

That'll work fine if your BPM doesn't expect a Web Service call.

You'll still need some querying though, if you need more than just info from the current object in context, i.e., combining info from multiple objects.
0
 

Author Comment

by:sumprit
Comment Utility
Thanks Bill.

let me try this now...and I will let u know in a short while.

thanks
0
 

Author Comment

by:sumprit
Comment Utility
Hi again,

I have a question regarding this statement?


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Is BPM system expecting a Web service call?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

We have decided on simple HTTP POST method? Is this not a good thing? What am I missing here?

 
0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
It's easier to implement in some cases (like Bill suggested), but it's a less flexible and scalable way to do it.  Don't worry too much about it.  You'll be fine either way.
0
 

Author Comment

by:sumprit
Comment Utility
Thanks techhealth.

Bill,

About what you mentioned earlier :-
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
For example, to pass all of the fields you listed above to some external system, you can just create a URL to the external system like this:

https://your_server/your_agent?id={!Opportunity.Id}&aid={!Opportunity.AccountId}&oname={!Opportunity.Name}

Then the code on the receiving end can just extract the values from the query string.
/////////////////////////////////////////////////////////////////////

Since, I do not have the URL address at this moment, can I still try out this option. Later, when I get the URL address I will edit it. This will help me understand it more better.

I am thinking like this:-

1.> Create a custom button, with Display Type = List Button
2.> Content Source = URL
3.> In the Body section, what should I mention?


0
 

Author Comment

by:sumprit
Comment Utility
I have found the answers to your questions:-

Answers to you questions to the best of my knowledge:

 

1.> BPM isnt taking, we are sending the information. So we need to use HTTP POST message only.

The key is, to get it into an HTTP POST message.

I guess you need to figure out how to make an HTTP POST message and then get Salesforce to put the correct data into that message to be sent to whatever address BPM wants us to send it to.

This is my requirement. and that is the reason why I created that S-Control. This S-control for now is only displaying data in a seperate window, later on when I get that BPM address I will edit it accordingly.

My question again is:-
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

How will I send the data from Salesforce to BPM system using the HTTP Post method?


thanks
0
 

Author Comment

by:sumprit
Comment Utility
looks like this problem is solved. Here is what I found from one of the research over the Apex Wiki network.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

You can do this using Salesforce SOA, in an S-Control, button, or link. If you have Unlimited Edition, you can also create calls using Http, HttpObject, and HttpResponse from the Apex Code object library. If you have the AJAX version, simply call the function in a place convenient for you. In Apex Code, you can't (unfortunately) use triggers, so you have to use a webservices method or use Apex AJAX to invoke the code via the Salesforce API through the browser. For example:

Code: {!RequireScript("/soap/ajax/11.1/connection.js"} postParams = {} postParams.url = 'http://www.mydomain.com/services/function' postParams.method = 'POST' postParams.requestData = 'data to send' // place your data here postParams.requestHeaders = {} postParams.requestHeaders['Content-Type'] = 'text/plain' //or another mime-type postParams.requestHeaders['Content-Length'] = postParams.requestData.length //required for POST postParams.onSuccess = processSuccess postParams.onError = processError sforce.connection.remoteFunction(postParams) function processSuccess(message) { // do something with results } function processError(message) { // do something with the error }
 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.
/////////////////////////////////////////////////////////////


Thank you so much.


Please check again, I will be posting more Sales force related queries.


regards to all.
0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
Salesforce SOA is certainly the way to go for SOAP based BPM endpoint.  But Bill's method is still way easier if your URL is a simple query string format.
0
 

Author Comment

by:sumprit
Comment Utility
Hi again,,


I did discuss Bills solution, which was:-

For example, to pass all of the fields you listed above to some external system, you can just create a URL to the external system like this:

https://your_server/your_agent?id={!Opportunity.Id}&aid={!Opportunity.AccountId}&oname={!Opportunity.Name}

Then the code on the receiving end can just extract the values from the query string.

    * Accept Multiple Solutions
    * Accept as Solution

===================================================================
===================================================================


1.> The problem is that I do not have any URL related information of the external system.

2.> Bill, is suggesting to write a code at the receiving end, however in real world I will not be able to access the external system.

3.> We just want to send data from Salesforce to the External system in a simple format. We dont care what is happening at the receiving end.

4.> This is the reason, HTTP POST method inside the S-control would be a best option.

If you still think otherwise, please let me know I am open to suggestions and thoughts.

Kind regards

0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
I guess you'll HAVE TO know a bit more about your receiving end.  If you're talking to a dog, speak cat is not gonna help. :)  You said "sending data to the external system in a simple format".  And what is that simple format?  Does your external system expect plain text parameters? Or does it expect SOAP messages?  The answer will decide what your put in your requestData, Content-Type, and so forth.

And if the remote system only needs plain parameters, then why bother with remoteFunction()?  A custom URL with merge fields will work fine.

Bill is not suggesting YOU writing the code at the receiving end.  He's just saying you need to know HOW the receiving end is going to consume your data, so you can tailor your output.  Tossing a lettuce to a hungry tiger won't be a proper feed for the beast.  :)
0
 

Author Comment

by:sumprit
Comment Utility
I need some time to give this a thought. It makes so much sense, but I need to find out a way to put this together and present this to the management.

I will post my reply again by weekend.

thanks
0
 

Author Comment

by:sumprit
Comment Utility
Can you please put a hold on this question.

I am still reviewing the suggestions provided by other experts, and that maybe the better option. I am not sure.

thanks
0
 

Author Comment

by:sumprit
Comment Utility
I would like to split points between - techhealth and Bill-hanson. they both make sense and I need to do more research on my part about this question.

Thanks guys.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I showed you how to use console view (HERE (http://www.experts-exchange.com/articles/18379/Getting-Started-and-Using-the-Salesforce-com-Console.html)) -– but how do you set it up on the admin side of Salesforce? Note that you have to have Admin leve…
Note: You must have administrative privileges in order to configure lead or case queues. Salesforce.com (http://www.Salesforce.com) is a cloud-based customer relationship management (CRM) system. It is widely used around the world by sales and ma…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now