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
Martin Chalot 15Martin Chalot 15 

Testing Multiple Webservice Callout in a single Transaction

Hello,
I'm trying to understand how can I test multiple webservice callout from a single transation. My transaction work like this :
- Step 1 : I call Web Service A. I get an ID from this Webservice
- Step 2 : From the Id I got from the webservice I call Webservice B
- Then I make some operations...

So far the only way to distinguish where the webservice is from is by making a condition on the endpoint :
global class ExpertiseMock implements HttpCalloutMock {
	global HTTPResponse respond(HTTPRequest req) {
        
        String content = null;
        String endpoint = req.getEndpoint();
        
        HttpResponse res = new HttpResponse();
        if(endpoint.startsWith('**********************************')) {
            res.setBody(ReponseA);
        } else {
            res.setBody(ReponseB);
        }
        
        res.setHeader('Content-Type', 'application/json');
        
        res.setStatusCode(200);
        return res;
    }
}

But I think it's not very clean. Is there another way ?

Thanks,

Regards,

Martin