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
ChervinChervin 

Rest Callout

Can anyone hele me ?
I have encountered a problem about rest api callout.
I have created a Apex Class annotated with '@RestResource',when a post request is recieved,I want to send a request to a third-party system via soap api(Callout),and after I recieved the response from this third party system,then make a response to the origin post request with the result responsed from the lately third party system,is it possible? Or how can I achieve this goal in another way?
Noviski, RodolfoNoviski, Rodolfo
Hi,
If I'm wrong please correct me!
But if you're trying to realize a SOAP request a Rest annotation class will not work.
Is your class will be available for Rest requests, the URL would look like this:

https://instance.salesforce.com/services/apexrest/ <service name>

If using SOAP, will need to create a new class and methods of webservice and generate a WSDL from that class.

Would you describe in more details about integration that is trying to accomplish?

Best Regards.
Rodolfo Noviski.
ChervinChervin
Hi,
Thanks for your kindly reply!

I have created a Apex class annotated as a REST resource class to receive post requests,I have also imported a WSDL file from SAP,and then generated a Apex class from this WSDL file,and this is a SOAP resource class,right?

The problem is,when I receive a post request from other systems,and I use the REST Apex class to handle the request,at this point,I want to make a callout using the SOAP Apex class,and using the result responsed by SOAP web services to response to the original post request,is this posssible?

SOAP callout in a REST Apex class,and code like this:

@RestResource(urlMapping = '/suburl')
global class RestApexClass{
    
    @HttpPost
    global static void handlePostRequest(){     //handle post resquests
        RestRequest req = RestContext.request;  //request
        RestResponse res = RestContext.response;    //response
        res.addHeader('Content-Type', 'text/plain');
        String reqBody = req.requestBody.toString();    //request string 
        String result = SoapClsss.SoapMethod(reqBody);   //SoapClass is an Apex class generated from a WSDL file    
        res.responseBody = Blob.valueOf(result);     //response to the post request  
    }
    
    
}