function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
radixweb@hotmail.comradixweb@hotmail.com 

How to call WCF RESTFul Service on Account(after update)

Hello Everyone, I am facing one problem, I would like to Call WCF RESTFull Service on Account(after update). I would like to create one XML file based on Accound updation. I have written given below Trigger. trigger trgUpdate on Account(after update) { Http http = new Http(); HttpRequest reqL = new HttpRequest(); reqL.setTimeout(60000); reqL.setEndpoint('http://restful.live2.dev.radixweb.net/RestServiceImpl.svc'); reqL.setMethod('GET'); reqL.setHeader('SOAPAction', 'http://restful.live2.dev.radixweb.net/RestServiceImpl.svc'); reqL.setHeader('SetHelloWorld', 'SFDC-Callout/22.0'); reqL.setHeader('Accept','text/xml'); reqL.setHeader('Content-type','text/xml'); reqL.setHeader('charset','UTF-8'); reqL.setBody('This is testing.'); try { HTTPResponse res = hL.send(reqL); System.debug(res.toString()); System.debug('STATUS:'+res.getStatus()); System.debug('STATUS_CODE:'+res.getStatusCode()); } catch(System.CalloutException e) { //Exception handling goes here.... } } // My WCF RESTFULL Service Method [OperationContract] [WebGet(UriTemplate = "/SetHelloWorld", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml)] void SetHelloWorld(); I am waiting for valuable feedback. Thanks.
Noam.dganiNoam.dgani

Hi

 

without getting to deep into your callout params, the first problem is that Salesforce does not allow you to perform a synchronous callout in the middle of a transaction (for instance - a trigger firing).

The solution is to perform the callout ASync (in salesforce terms - invoke a @future anotated record).

 

please see your code below with a small adjustment:

 

trigger trgUpdate on Account(after update) 
{ 
	
	execute();

	@future
	private void execute()
	{
		Http http = new Http(); 
		HttpRequest reqL = new HttpRequest(); 
		reqL.setTimeout(60000); 
		reqL.setEndpoint('http://restful.live2.dev.radixweb.net/RestServiceImpl.svc'); 
		reqL.setMethod('GET'); 
		reqL.setHeader('SOAPAction', 'http://restful.live2.dev.radixweb.net/RestServiceImpl.svc'); 
		reqL.setHeader('SetHelloWorld', 'SFDC-Callout/22.0'); 
		reqL.setHeader('Accept','text/xml'); 
		reqL.setHeader('Content-type','text/xml'); 
		reqL.setHeader('charset','UTF-8'); 
		reqL.setBody('This is testing.'); 
		try { 
			HTTPResponse res = hL.send(reqL); 
			System.debug(res.toString()); 
			System.debug('STATUS:'+res.getStatus()); 
			System.debug('STATUS_CODE:'+res.getStatusCode()); 
		} 
		catch(System.CalloutException e) 
		{ 
			//Exception handling goes here.... 
		}
	}
}