• Teboda
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Hi all. I'm fairly new to saleforce development, and perhaps I've structured this all wrong. But here is what I have and what I would like to do:

 

I have a VisualForce page that is an extension of the Asset page. One of the fields, the serialnumber, needs to be filled in automatically based on parameters set on the parent Account along with the Product that the user selects for the asset. So, at the moment the user can select a product and I have a function that resolves the serialnumber when the product is selected. 

 

To do this I must access code running on our web server and so I have made a WebService that accepts a request from SalesForce with the required parameters. As far as I've understood it, the function in my Apex class that calls the function of my SOAP class has to be declared as 

@future(callout=true)

 and will be called asynchronously.

 

So far so good, my function is called when an update button is pressed in the VisualForce page and the page is updated. However, since the call is asynchonous it hasn't returned yet, so now I'm thinking that in order to get the generated serialnumber (which I store in a static global variable of the Apex class) I need to have the asynchronous function somehow notify the VisualForce page when it returns... how do I do that? Or should this be done differently all toghether? 

 

Hi all. 

 

I'm trying to implement a web service (hosted on one of our companies web servers) that can be called from Salesforce to receive license information from our licensing system that should then be stored in SalesForce. So, this is a webservice called from within SalesForce and not the other way around (which judging by the examples I found seems to be the the most common case).

 

At first I was getting javescript errors due to no sessionId being set for sforce.connection (?) which I was able to debug in Visual Studio. This was resolved by adding a call to sforce.connection.login however I am still getting a http error 500 on the call. It works perfectly fine if called by performing a POST from a stand-alone HTML-page but not from within Salesforce. Am I missing some vital step? Here's my test S-control which requests a specific serial number from the webservice:

 

 

<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>

<script type="text/javascript">

sforce.connection.login("john.doe@somecompany.com", "passwordSECURITYTOKEN");

function GetWsSn(){

var envelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +

' xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +

' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ' +

' <soap:Body> ' +

' <Generate xmlns="http://MyXMLWebServiceNameSpace/"> ' +

' <outSN></outSN> ' +

' <inCountry>1</inCountry> ' +

' <inPartner>1</inPartner> ' +

' <inCount>1</inCount> ' +

' <inPrefix>NSS</inPrefix> ' +

' </Generate> ' +

' </soap:Body> ';

var request = null;sforce.connection.remoteFunction({

url : "http://85.226.44.189/northernweblicex/SerialNumber.asmx",

requestHeaders: {

"Content-Type": "text/xml; charset=utf-8",

"SOAPAction": "http://NorthernWebLicEx.northern.net/Generate"

},

mimeType: "text/xml",

requestData: envelope,

method: "POST",

onSuccess : function(response, _request) {

document.getElementById("result").value = response.GenerateResult;

},

onFailure : function(response, request) {

document.getElementById("result").value = "Failed " + response + "\n" + request.getAllResponseHeaders();

}

});

}</script>

<body>

Country 1 <select id="country1"></select>

Country 2 <select id="country2"></select>

<input type="button" value="Get Rate" onclick="javascript&colon; GetWsSn();" />

<br><br>Results<br>

<textarea rows="10" id="result" cols="80"></textarea>

</body>

 

 

 

Message Edited by Teboda on 04-20-2009 02:04 AM
  • April 20, 2009
  • Like
  • 0

Hi all. I'm fairly new to saleforce development, and perhaps I've structured this all wrong. But here is what I have and what I would like to do:

 

I have a VisualForce page that is an extension of the Asset page. One of the fields, the serialnumber, needs to be filled in automatically based on parameters set on the parent Account along with the Product that the user selects for the asset. So, at the moment the user can select a product and I have a function that resolves the serialnumber when the product is selected. 

 

To do this I must access code running on our web server and so I have made a WebService that accepts a request from SalesForce with the required parameters. As far as I've understood it, the function in my Apex class that calls the function of my SOAP class has to be declared as 

@future(callout=true)

 and will be called asynchronously.

 

So far so good, my function is called when an update button is pressed in the VisualForce page and the page is updated. However, since the call is asynchonous it hasn't returned yet, so now I'm thinking that in order to get the generated serialnumber (which I store in a static global variable of the Apex class) I need to have the asynchronous function somehow notify the VisualForce page when it returns... how do I do that? Or should this be done differently all toghether? 

 

Hi all. 

 

I'm trying to implement a web service (hosted on one of our companies web servers) that can be called from Salesforce to receive license information from our licensing system that should then be stored in SalesForce. So, this is a webservice called from within SalesForce and not the other way around (which judging by the examples I found seems to be the the most common case).

 

At first I was getting javescript errors due to no sessionId being set for sforce.connection (?) which I was able to debug in Visual Studio. This was resolved by adding a call to sforce.connection.login however I am still getting a http error 500 on the call. It works perfectly fine if called by performing a POST from a stand-alone HTML-page but not from within Salesforce. Am I missing some vital step? Here's my test S-control which requests a specific serial number from the webservice:

 

 

<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>

<script type="text/javascript">

sforce.connection.login("john.doe@somecompany.com", "passwordSECURITYTOKEN");

function GetWsSn(){

var envelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +

' xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +

' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ' +

' <soap:Body> ' +

' <Generate xmlns="http://MyXMLWebServiceNameSpace/"> ' +

' <outSN></outSN> ' +

' <inCountry>1</inCountry> ' +

' <inPartner>1</inPartner> ' +

' <inCount>1</inCount> ' +

' <inPrefix>NSS</inPrefix> ' +

' </Generate> ' +

' </soap:Body> ';

var request = null;sforce.connection.remoteFunction({

url : "http://85.226.44.189/northernweblicex/SerialNumber.asmx",

requestHeaders: {

"Content-Type": "text/xml; charset=utf-8",

"SOAPAction": "http://NorthernWebLicEx.northern.net/Generate"

},

mimeType: "text/xml",

requestData: envelope,

method: "POST",

onSuccess : function(response, _request) {

document.getElementById("result").value = response.GenerateResult;

},

onFailure : function(response, request) {

document.getElementById("result").value = "Failed " + response + "\n" + request.getAllResponseHeaders();

}

});

}</script>

<body>

Country 1 <select id="country1"></select>

Country 2 <select id="country2"></select>

<input type="button" value="Get Rate" onclick="javascript&colon; GetWsSn();" />

<br><br>Results<br>

<textarea rows="10" id="result" cols="80"></textarea>

</body>

 

 

 

Message Edited by Teboda on 04-20-2009 02:04 AM
  • April 20, 2009
  • Like
  • 0

The AJAX Proxy remoteFunction fails when posting multipart/form-data. This may be related to a previousily reported bug: Bug #192181

 

Here is the remoteFunction code:

function uploadTest(){

var content = '--7777777';
content += '\r\nContent-Disposition: form-data; name="file"; filename="test.txt"';
content += '\r\nContent-Type: text/plain';
content += '\r\n\r\n Test Test Test';
content += '\r\n--7777777--';

sforce.connection.remoteFunction({
url: 'http://test.com',
requestHeaders:{
"Content-Type": "multipart/form-data; boundary=7777777"
},
requestData: content,
method: "POST",
onSuccess : function(response) {
alert("Success: " + response);
},
onFailure : function(response) {
alert("Failure: " + response);
}
});
}

 

And, here is the response:

<html>
<head><title>400 Unable to forward request due to: Read timed out</title></head>
<body>
<h1>400 Unable to forward request due to: Read timed out</h1>
<p /><hr />
<small>

</small>
</body></html>

 

When the remoteFunction method is changed to GET, the request is successfully sent to the host without the requestData.  A possible solution may be to allow the sending of requestData with a GET method or allowing multipart/form-data to be set as the Content-Type in requestHeaders.

 

Note: Sending the same request with an Apex HttpRequest works perfectly.  However, the 100kb size limit makes it a non-viable solution.

 

Any assistance in getting the remoteFunction to work properly would be greatly appreciated!

 

-Thanks

 

 

 

 

  • April 01, 2009
  • Like
  • 0