2

I want to encapsulate a WebServiceCallout.invoke to reuse it in various cases, so I've build the following static method

public static Object callSOAP(Object stub, Object request_x, Map<String, Object> response_map_x, Object response_x, String endpoint_x, String soapAction, String reqNameSpace, String reqName, String resNameSpace, String resName, String resType) {

    response_map_x.put('response_x', response_x);

    WebServiceCallout.invoke(
        stub,
        request_x,
        response_map_x,
        new String[]{
            endpoint_x,
            soapAction,
            reqNameSpace,
            reqName,
            resNameSpace,
            resName,
            resType
        }
    );

    response_x = response_map_x.get('response_x');

    return response_x;
}

However when I try to save this I get the following error:

Variable does not exist: WebServiceCallout 

Like if some parameter is not valid and the system's class is not being recognised. According to the docs the parameters type are correct so no idea why this is failing or is there something I'm missing?.

2

1 Answer 1

0

Your code will work when stub and request_x object have specific type. Define StubBaseObject and RequestBaseObject:

public abstract class StubBaseObject{}
public abstract class RequestBaseObject{}

public static Map<String, Object> callSOAP(StubBaseObject stub, RequestBaseObject request_x, Map<String, Object> response_map_x, String endpoint_x, String soapAction, String reqNameSpace, String reqName, String resNameSpace, String resName, String resType) {
    WebServiceCallout.invoke(
            stub,
            request_x,
            response_map_x,
            new String[]{
                    endpoint_x,
                    soapAction,
                    reqNameSpace,
                    reqName,
                    resNameSpace,
                    resName,
                    resType
            }
    );

    return response_map_x;
}

In Class that use callSOAP method you must extend specific stub class with StubBaseObject and specific request class with RequestBaseObject.

1
  • I like this approach. Do you have a full example of this?
    – Robs
    Commented Jan 8, 2019 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .