You need to sign in to do that
Don't have an account?
how to call web services functions into APEX triggers
Hi,
I am creating .net Sample (Helloworld) Webservices, & converted to APEX classes.,
Now how to call that that helloworld functions in APEX triggers???
My sample code of APEX Class is:
//Generated by wsdl2apex
public class Hello {
public class HelloWorld_element {
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
private String[] field_order_type_info = new String[]{};
}
public class ServiceSoap {
public String endpoint_x = 'http://172.16.10.114/SFSample/SFSample.asmx';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://tempuri.org/', 'Hello'};
public String HelloWorld() {
Hello.HelloWorld_element request_x = new Hello.HelloWorld_element();
Hello.HelloWorldResponse_element response_x;
Map<String, Hello.HelloWorldResponse_element> response_map_x = new Map<String, Hello.HelloWorldResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://tempuri.org/HelloWorld',
'http://tempuri.org/',
'HelloWorld',
'http://tempuri.org/',
'HelloWorldResponse',
'Hello.HelloWorldResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.HelloWorldResult;
}
}
public class HelloWorldResponse_element {
public String HelloWorldResult;
private String[] HelloWorldResult_type_info = new String[]{'HelloWorldResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
private String[] field_order_type_info = new String[]{'HelloWorldResult'};
}
}
Now how to call that Helloworld function to APEX triggers???
Thanks,
Krishna.
Hi,
To call the webservice you need to create another apex class, in which you need to create the object of your webservice and then call the web method using that object. Also the functions in class should be static and must have "future" as the attribute
@future (callout=true)
//Update user info
public static void testfunc(){
}
Also this apex class must have proper test method defined.
And in trigger, call the newly method of the new apex class which would then invoke your webservice.
Hope this would help!
Regards,
Shaveta
Hi Shaveta,
Here i am also trying to Integrate .Net Webservice from Salesforce,
As @Future is only for static void methods, we are not able to return a value like whether the message is sent successfully or any exception Occurs.
I have a trigger on the Account Object that calls a class. That class then calls another class that makes an HTTP GET request to a .Net Web Service.
However I get the error:
"Callout from triggers are currently not supported".
How can I send data to an external Web Service using Apex code?
Any other Ideas?
Thanks in advance..
Anbu_KS
Hi Anbu_KS,
I think every developer has encountered such a problem.
And maybe for you it's not true, but for those who do not know the solution I poazhu as I walked around the restriction.
I have two methods in class:
global with sharing class myCallOuts {
public static void myCallOutReal(List<String> lid) {
HTTP http;
HTTPRequest req;
HTTPResponse res;
...
req.setEndpoint('http://someaddress.ru/ConnectorService'); req.setHeader('SOAPAction', soapAction); // Here some SoapAction
req.setBody(soapRequest); // Here XML body of request
http = new Http();
try {
res = http.send(req);