Activity Forums Salesforce® Discussions How to specify multiple responses in SOAP callout? Reply To: How to specify multiple responses in SOAP callout?

  • Vikas Kumar

    February 14, 2017 at 7:23 am

    Hi sushant,

    You could create a constructor for example:

    global class PuchaseWSMock_IsTest implements WebServiceMock {

    public String type;

    global PuchaseWSMock_IsTest(final String type){
    this.type = type;

    global void doInvoke(Object stub,
    Object request,
    Map<String, Object> response,
    String endpoint,
    String soapAction,
    String requestName,
    String responseNS,
    String responseName,
    String responseType) {

    if(type == 'A'){
    //set response for web service method 1
    PurchaseWS.ProgramInfoResponse responseElementA = new PurchaseWS.ProgramInfoResponse();
    responseElement.AgreementID = 344;
    response.put('response_x', responseElementA);
    //set response for web service method2?
    if(type == 'B'){
    //set response for web service method 2
    PurchaseWS.ProgramInfoResponse responseElementB = new PurchaseWS.ProgramInfoResponse();
    responseElement.AgreementID = 100;
    response.put('response_x', responseElementB);

    Test method:
    static testMethod void myTestA() {
    Test.setMock(WebServiceMock.class, new PurchaseWSMock_IsTest('A'));

    //call web service method 1

    static testMethod void myTestB() {
    Test.setMock(WebServiceMock.class, new PurchaseWSMock_IsTest('B'));

    //call web service method 2