You need to sign in to do that
Don't have an account?
saravana
Help in making webservice calls using connection.js
Hi,
I am having a problem in making calls to webservice methods using the sforce.apex.execute method.
The exception i get is
Error {faultcode:'sf:INVALID_SESSION_ID', faultstring:'INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session', line:'1019', sourceURL:'https://na5.salesforce.com/soap/ajax/13.0/connection.js', }
I wrote a javascript to call webservice method passing arguments to save it in my server.
/////////////////////////////////////////////////////////////////////////////////////
function call()
{
var mess= sforce.apex.execute('MyController','getSend',{cname:document.getElementById('cname').value,email:document.getElementById('cmail').value,phone:document.getElementById('cphone').value,product:products});
}
/////////////////////////////////////////////////////////////////////////////////////
The controller contains the webservice method defined.
/////////////////////////////////////////////////////////////////////////////////////
WebService static String getSend(String cname,String email,String phone,String product) {
System.debug('inside send '+cname );
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
//req.setHeader('Cookie','sid='+UserInfo.getSessionId());
//+'&product='+product
req.setEndpoint('http://www.iclub.in/MRUserTrail/insert.html? userName='+UserInfo.getUserName()+'&cname='+cname+'&cemail='+email+'&cphone='+phone+'&product='+product);
HttpResponse res = h.send(req);
System.debug(res.getBody());
XmlStreamReader reader = res.getXmlStreamReader();
while(reader.hasNext()) {
if (reader.getEventType() == XmlTag.START_ELEMENT) {
if(reader.getLocalName()=='status')
{
reader.next();
if(reader.getText()=='FAILURE')
{
reader.next();reader.next();reader.next();
return 'f$'+reader.getText();
}
if(reader.getText()=='SUCCESS')
{
reader.next();reader.next();reader.next();
return 's$'+reader.getText();
}
}
}
reader.next();
}
return 'f$Please try again after some time';
}
/////////////////////////////////////////////////////////////////////////////////////
I used this sforce.apex.execute because there was not way to call an controller method by passing
an argument's to it.I tried various ways of callling the controller but i could not do so. If it is
just an normal method without parameters then we can call it using !${Accounts.name}.
Q.Please tell me is there a way to call controller methods by passing parameters to it?
Q2.Please help me on this exception i am getting when calling the javascript function.
Thaking You everyone.
I am having a problem in making calls to webservice methods using the sforce.apex.execute method.
The exception i get is
Error {faultcode:'sf:INVALID_SESSION_ID', faultstring:'INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session', line:'1019', sourceURL:'https://na5.salesforce.com/soap/ajax/13.0/connection.js', }
I wrote a javascript to call webservice method passing arguments to save it in my server.
/////////////////////////////////////////////////////////////////////////////////////
function call()
{
var mess= sforce.apex.execute('MyController','getSend',{cname:document.getElementById('cname').value,email:document.getElementById('cmail').value,phone:document.getElementById('cphone').value,product:products});
}
/////////////////////////////////////////////////////////////////////////////////////
The controller contains the webservice method defined.
/////////////////////////////////////////////////////////////////////////////////////
WebService static String getSend(String cname,String email,String phone,String product) {
System.debug('inside send '+cname );
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
//req.setHeader('Cookie','sid='+UserInfo.getSessionId());
//+'&product='+product
req.setEndpoint('http://www.iclub.in/MRUserTrail/insert.html? userName='+UserInfo.getUserName()+'&cname='+cname+'&cemail='+email+'&cphone='+phone+'&product='+product);
HttpResponse res = h.send(req);
System.debug(res.getBody());
XmlStreamReader reader = res.getXmlStreamReader();
while(reader.hasNext()) {
if (reader.getEventType() == XmlTag.START_ELEMENT) {
if(reader.getLocalName()=='status')
{
reader.next();
if(reader.getText()=='FAILURE')
{
reader.next();reader.next();reader.next();
return 'f$'+reader.getText();
}
if(reader.getText()=='SUCCESS')
{
reader.next();reader.next();reader.next();
return 's$'+reader.getText();
}
}
}
reader.next();
}
return 'f$Please try again after some time';
}
/////////////////////////////////////////////////////////////////////////////////////
I used this sforce.apex.execute because there was not way to call an controller method by passing
an argument's to it.I tried various ways of callling the controller but i could not do so. If it is
just an normal method without parameters then we can call it using !${Accounts.name}.
Q.Please tell me is there a way to call controller methods by passing parameters to it?
Q2.Please help me on this exception i am getting when calling the javascript function.
Thaking You everyone.
I want to pass parameters (String arguments) into the controller and i could not find any other way to do so. Thats why i used Connection.js.
If there's any want please tell me.
Thanks Emad Salman for your quick reply.
Alternatively, if the arguments are based on user input, you can capture the input using components like inputText etc. and have the value available to you in apex properties/variables without the need of passing parameters.