Integration consists of 11% of total score in Salesforce Platform Dev II Exam. This chapter basically revolves around Apex with these two famous web services: SOAP and REST.

NOTE: This post is written in July 2019 and content might be changed/updated overtime. The content is inspired by focusonforce.com.

Callout to Web Services

  • Named credential can be setup in order to make a callout to external site.
  • NOTE: if using named credential, remote site setting will not be required.
  • Create name credential by navigating to Setup > Named Credentials:
    create-named-credential
  • Create remote site settings by navigating to Setup > Remote Site Settings:
    create-remote-site-settings

REST Web Service

  • Apex class can be defined as global and global static for its method in order to use as REST web service.
  • The class should be annotated with @RestResource and urlMapping value should be specified.
  • URL mapping is case-sensitve and is appended to the base endpoint.
  • Global Static keywords are required for exposing HTTP method and it should be annotated:
    • @HttpGet - read or retrieve records
    • @HttpPost - create records
    • @HttpDelete - delete records
    • @HttpPut - upsert records
    • @HttpPatch - update fields in existing records
  • Example of REST web service:
@RestResource(urlMapping='/Account/*')

global with sharing class AccountRest{
    
    @HttpGet
    global static String getAccName(){
        String name;
        // retrieve name 
        return name;
    }
}

Http, HttpRequest, and HttpResponse class

  • Http class is used to initiate an HTTP request and response using send() method
  • HttpRequest class is used to instantiate a HTTP request and it can set neccessary parts of the request before sending the request:
    • setEndpoint() - set endpoint url
    • setMethod() - set the type of method, such as GET, POST, PUT, DELETE, HEAD and TRACE
    • setHeader() - set the content of request header (allow setting different name-value pairs)
    • setBody() - set the content of request body
    • setTimeout() - set timeout in milliseconds (default is 10 seconds, max is 120 seconds)
  • HttpResponse class is used to assign with the response:
    • getBody() - get the response body
    • getStatus() - get the response status message
    • getStatusCode() - get the response status code (200, 400, 500...)
  • Sample callout to external service using HTTP:
HttpRequest request = new HttpRequest();
request.setEndpoint('https://test.com/api');
request.setMethod('GET');
request.setBody('hello=world');
Http http = new Http();
HttpResponse response = http.send(request);
System.debug(response.getStatus() + ', ' + response.getBody());

JSON, JSONGenerator, and JSONParser class

  • JSON class can be used to serialize and deserialize standard and custom objects, Apex classes, primitive and collection types, and database method return types such as SaveResult.
  • Sample of returning SaveResults through updating metadata(s):
    • SaveResult [] srs = metabinding.upateMetadata(Metadata [] metadatas);
  • JSON class methods:
    • createParser() - creator JSON parser
    • serialize() - serialization
    • deserialize() - deserialization
    • NOTE: please refer to the official documentation here.
  • JSONGenerator class can be used to generate standard JSON-encoded content and that JSON content can be constructed element by element.
  • JSONGenerator class methods:
    • getAsString() - return JSON content in String
    • writeBlob(blobValue)
    • writeBlobField(fieldName, blobValue)
    • writeBoolean(booleanValue)
    • writeBooleanField(fieldName, booleanValue)
    • writeDate(dateValue)
    • writeDateField(fieldName, dateValue)
    • writeDateTime(dateTimeValue)
    • writeDateTimeField(fieldName, dateTimeValue)
    • writeId(idValue)
    • writeIdField(fieldName, idValue)
    • writeNumber(numValue)
    • writeNumberField(fieldName, numValue)
    • writeObject(object)
    • writeObjectField(fieldName, object)
    • writeString(stringValue)
    • writeStringField(fieldName, stringValue)
    • writeTime(timeValue)
    • writeTimeField(fieldName, timeValue)
    • writeNull()
    • writeNullField(fieldName)
    • writeFieldName(fieldName)
    • writeStartArray() - write '['
    • writeEndArray() - write ']'
    • writeStartObject() - write '{'
    • writeEndObject() - write '}'
public class Test{
    String grade;
    public Test(String grade){
        this.grade = grade;
    }
}

String name = 'hello';
String value = 'world';
List<String> list = new List<String>();
list.add('a');
list.add('b');
list.add('c');
Test test = new Test('A');


JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();

gen.writeStringField(name, value);

gen.writeFieldName('array');
gen.writeStartArray();  
gen.writeStartObject() ;
gen.writeNumberField('number', 1);
gen.writeBooleanField('boolean', false);
gen.writeEndObject();
gen.writeEndArray();

gen.writeFieldName('list');
gen.writeStartObject();
gen.writeObjectField('list', list);
gen.writeEndObject();

gen.writeFieldName('test');
gen.writeObject(test);
gen.writeEndObject();

gen.writeEndObject();
String jsonStr = gen.getAsString();
System.debug(jsonStr);
  • JSONParser class can be used to parse JSON-encoded content, mostly used in the JSON response from web service callout.
  • JSONParser class methods:
    • getBlobValue()
    • getBooleanValue()
    • getDateValue()
    • getDatetimeValue()
    • getDecimalValue()
    • getIdValue()
    • getIntegerValue()
    • getLongValue()
    • getTimeValue()
    • getText() - return the textual representation of current token, null if no current token
    • hasCurrentToken() - return true if parser points to a token
    • nextToken() - return next token
    • nextValue() - return next token value
  • Example of parsing JSON formatted content:
JSONParser parser = JSON.createParser(response.getBody());
String temp;
while(parser.nextToken() != null){
    temp = parser.getText();
    System.debug(temp);
}
  • Something about JSON:
    • null must be in all lowercase, NULL is not a valid keyword in JSON
    • double quote '"' is the standard for JSON

SOAP Web Service

  • Apex class can be defined as global and keyword static for its method in in order to use as SOAP web service.
  • You can use the webservice modifier to define top-level, outer class methods and variables, and member variables of an inner class.
  • NOTE: webservice cannot be used on a class itself, or an interface or interface methods or variables.
  • NOTE: Only static method can be marked with webservice keyword and that exposed methods and variables must have webservice keyword.
  • WSDL file for Apex can be generated from Apex class page in Setup if your Apex class supports webservice methods.
    generate-WSDL
  • Methods in Apex class will be called from external application by consuming the class WSDL file.
global with sharing class TestingSoapClass {

    webservice static String getAccountName(String id){

        return [SELECT Id FROM Account WHERE Id = :id LIMIT 1].Name;

    }
}
  • WSDL2Apex utility can generate Apex class from WSDL file by navigating to Apex Classes in Setup.
    1. Download and upload WSDL file (1MB max)
      generate-from-WSDL-1
    2. Generate Apex code
      generate-from-WSDL-2
    3. Done! You can find calculatorServices (synchronous) and AsyncCalculatorServices (aynchronous) Apex class.
      generate-from-WSDL-3
  • Link to this calculator example can be found in Salesforce Trailhead. Source files can be found in #Apendix (all the way to the bottom).
  • An instance of the stub can be created in Apex code to invoke an external service using WSDL.
calculatorServices.CalculatorImplPort calc = new calculatorServices.CalculatorImplPort();
Double a = 13.0;
Double b = 7.0;
Double c = calc.doMultiply(a, b);
  • NOTE: each complex type in WSDL becomes a class while each element becomes public field in the class.
  • NOTE: Each WSDL operation is mapped to a Apex class method.
  • NOTE: Define any method that uses the webservice keyword as static, but not on the variables (just webservice only for variables).
  • Methods defined with the webservice keyword cannot take the following elements as parameters nor returned values:
    • Map
    • Set
    • Pattern, Matcher and Exception objects

Metadata API

  • Metadata API can be used to retrieve, deploy, create, update, or delete customization information, such as custom object definition, page layout and etc.
  • Typical use cases of Metadata API:
    • export metadata information as XML metadata files
    • use retrieve() and deploy() to move XML metadata files between orgs.
    • modify existing customizations
    • CRUD setup and configuration components
    • useful for ISVs as it allows app configuration and streamlines the upgrade process with a user-friendly interface

Streaming API

  • Streaming API is used to push notifications from server to client based on defined criteria.
  • Benefits of using Streaming API:
    • reduce the need for constant polling by applications, hence reducing API calls and processing time
    • sync data with Salesforce
    • process business logic in an external system instead of in Salesforce
  • Streaming API uses Bayuex protocol and CometD for long polling:
    • Bayuex protocol - transport message via HTTP asynchronously
    • CometD - scalable HTTP-based event routing bus that implements the Bayuex protocol and uses AJAX push technology pattern known as Comet
  • Long polling process:
    1. Client sends request to server
    2. Server holds request until information is available
    3. Server sends response back to client when information is available
    4. Client sends request to server again
    5. Client maintains connection to server and always wait to receive response.
  • PushTopic channel can be created (channel created automatically when PushTopic is created) to setup subscription with the following properties:
    • Name - name in the channel element of event notice (full channel name will be "/topic/channelName")
    • Query - SOQL string query
    • API Version - version 37 and above can retrieve events published in previous 24 hours.
  • NOTE: for API 37 and above, the replayId setting has the possible options:
    • specific replayId value - retrieve events with the replayId
    • -1 - receive new events since the subscription began
    • -2 - receive new events and any events from the past 24 hours
  • NOTE: PushTopic can be set to notify all by setting pushTopicNotifyForFields = 'All';
  • With PushTopic, it is possible to generate notifications for Create, Update, Delete and Undelete.
PushTopic p = new PushTopic();
p.Name = 'OpportunityNotification';
p.Query = 'SELECT Id, Name, StageName FROM Opportunity WHERE StageName = \'Closed Won\'';
p.ApiVersion = 37.0;
insert p;
  • Generic streaming can be setup for sending and receiving custom notifications for events that are external to Salesforce, using Streaming API to send notifications of general events that are not tied to Salesforce data change.
  • With all that, a StreamingChannel needs to be created ( channel name will be like "/u/channelName").
  • Steps to use Generic Streaming:
    • Create a Streaming Channel
    • Clients subscribe to channel
    • Streaming Channel Push REST API resources to send notifications

Analytics API

  • Analytics API allows programmatic access to feature such as datasets, dashboards and lenses.
  • NOTE: Analytics API is actually based on Chatter REST API, allowing create, update and retrieve Analytics dashboards using Analytics API.
  • SAQL (Salesforce Analytics Query Language) can be used to pull data from Analytics datasets.
  • Analytics SDK tools allow building and sending Analytics queries:
    • Wave.QueryBuilder can be used to construct SAQL query string
    • Statements can be sued with Wave.QueryBuilder:
      • load dataset
      • foreach
      • group
      • order
      • limit
      • filter
      • min, max, count, avg, unique, as, sum
    • Wave.ProjectionNode and Wave.QueryNode can be used to build a more advanced query if Wave.QueryBuilder is not enough.
    • ConnectApi.Wave.executeQuery() passes a SAQL query from Apex to Analytics and receive a JSON-formatted response.
<!-- display report chart in visualforce -->
<apex:page>
    <apex:pageBlock title="Account">
        <apex:pageBlockSection>
            <analytics:reportChart reportId="00O3900000KJK" size="small" />
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Apendix

  • WSDL file: calculator.xml:
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://calculator.services/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="CalculatorImplService" targetNamespace="http://calculator.services/">
  <wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://calculator.services/" elementFormDefault="unqualified" targetNamespace="http://calculator.services/" version="1.0">

  <xs:element name="doAdd" type="tns:doAdd"/>

  <xs:element name="doAddResponse" type="tns:doAddResponse"/>

  <xs:element name="doDivide" type="tns:doDivide"/>

  <xs:element name="doDivideResponse" type="tns:doDivideResponse"/>

  <xs:element name="doMultiply" type="tns:doMultiply"/>

  <xs:element name="doMultiplyResponse" type="tns:doMultiplyResponse"/>

  <xs:element name="doSubtract" type="tns:doSubtract"/>

  <xs:element name="doSubtractResponse" type="tns:doSubtractResponse"/>

  <xs:complexType name="doDivide">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="xs:double"/>
      <xs:element minOccurs="0" name="arg1" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doDivideResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doSubtract">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="xs:double"/>
      <xs:element minOccurs="0" name="arg1" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doSubtractResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doMultiply">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="xs:double"/>
      <xs:element minOccurs="0" name="arg1" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doMultiplyResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doAdd">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="xs:double"/>
      <xs:element minOccurs="0" name="arg1" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="doAddResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:double"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
  </wsdl:types>
  <wsdl:message name="doSubtractResponse">
    <wsdl:part element="tns:doSubtractResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doMultiplyResponse">
    <wsdl:part element="tns:doMultiplyResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doAddResponse">
    <wsdl:part element="tns:doAddResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doDivide">
    <wsdl:part element="tns:doDivide" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doSubtract">
    <wsdl:part element="tns:doSubtract" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doDivideResponse">
    <wsdl:part element="tns:doDivideResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doMultiply">
    <wsdl:part element="tns:doMultiply" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="doAdd">
    <wsdl:part element="tns:doAdd" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="Calculator">
    <wsdl:operation name="doDivide">
      <wsdl:input message="tns:doDivide" name="doDivide">
    </wsdl:input>
      <wsdl:output message="tns:doDivideResponse" name="doDivideResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="doSubtract">
      <wsdl:input message="tns:doSubtract" name="doSubtract">
    </wsdl:input>
      <wsdl:output message="tns:doSubtractResponse" name="doSubtractResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="doMultiply">
      <wsdl:input message="tns:doMultiply" name="doMultiply">
    </wsdl:input>
      <wsdl:output message="tns:doMultiplyResponse" name="doMultiplyResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="doAdd">
      <wsdl:input message="tns:doAdd" name="doAdd">
    </wsdl:input>
      <wsdl:output message="tns:doAddResponse" name="doAddResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="CalculatorImplServiceSoapBinding" type="tns:Calculator">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="doDivide">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="doDivide">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="doDivideResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="doSubtract">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="doSubtract">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="doSubtractResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="doMultiply">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="doMultiply">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="doMultiplyResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="doAdd">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="doAdd">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="doAddResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="CalculatorImplService">
    <wsdl:port binding="tns:CalculatorImplServiceSoapBinding" name="CalculatorImplPort">
      <soap:address location="https://th-apex-soap-service.herokuapp.com/service/calculator"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
  • Apex class: calculatorSevices.cls:
//Generated by wsdl2apex

public class calculatorServices {
    public class doDivideResponse {
        public Double return_x;
        private String[] return_x_type_info = new String[]{'return','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class doMultiply {
        public Double arg0;
        public Double arg1;
        private String[] arg0_type_info = new String[]{'arg0','http://calculator.services/',null,'0','1','false'};
        private String[] arg1_type_info = new String[]{'arg1','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'arg0','arg1'};
    }
    public class doAdd {
        public Double arg0;
        public Double arg1;
        private String[] arg0_type_info = new String[]{'arg0','http://calculator.services/',null,'0','1','false'};
        private String[] arg1_type_info = new String[]{'arg1','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'arg0','arg1'};
    }
    public class doAddResponse {
        public Double return_x;
        private String[] return_x_type_info = new String[]{'return','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class doDivide {
        public Double arg0;
        public Double arg1;
        private String[] arg0_type_info = new String[]{'arg0','http://calculator.services/',null,'0','1','false'};
        private String[] arg1_type_info = new String[]{'arg1','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'arg0','arg1'};
    }
    public class doSubtract {
        public Double arg0;
        public Double arg1;
        private String[] arg0_type_info = new String[]{'arg0','http://calculator.services/',null,'0','1','false'};
        private String[] arg1_type_info = new String[]{'arg1','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'arg0','arg1'};
    }
    public class doSubtractResponse {
        public Double return_x;
        private String[] return_x_type_info = new String[]{'return','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class doMultiplyResponse {
        public Double return_x;
        private String[] return_x_type_info = new String[]{'return','http://calculator.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://calculator.services/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class CalculatorImplPort {
        public String endpoint_x = 'https://th-apex-soap-service.herokuapp.com/service/calculator';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://calculator.services/', 'calculatorServices'};
        public Double doDivide(Double arg0,Double arg1) {
            calculatorServices.doDivide request_x = new calculatorServices.doDivide();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            calculatorServices.doDivideResponse response_x;
            Map<String, calculatorServices.doDivideResponse> response_map_x = new Map<String, calculatorServices.doDivideResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doDivide',
              'http://calculator.services/',
              'doDivideResponse',
              'calculatorServices.doDivideResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
        public Double doSubtract(Double arg0,Double arg1) {
            calculatorServices.doSubtract request_x = new calculatorServices.doSubtract();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            calculatorServices.doSubtractResponse response_x;
            Map<String, calculatorServices.doSubtractResponse> response_map_x = new Map<String, calculatorServices.doSubtractResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doSubtract',
              'http://calculator.services/',
              'doSubtractResponse',
              'calculatorServices.doSubtractResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
        public Double doMultiply(Double arg0,Double arg1) {
            calculatorServices.doMultiply request_x = new calculatorServices.doMultiply();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            calculatorServices.doMultiplyResponse response_x;
            Map<String, calculatorServices.doMultiplyResponse> response_map_x = new Map<String, calculatorServices.doMultiplyResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doMultiply',
              'http://calculator.services/',
              'doMultiplyResponse',
              'calculatorServices.doMultiplyResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
        public Double doAdd(Double arg0,Double arg1) {
            calculatorServices.doAdd request_x = new calculatorServices.doAdd();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            calculatorServices.doAddResponse response_x;
            Map<String, calculatorServices.doAddResponse> response_map_x = new Map<String, calculatorServices.doAddResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doAdd',
              'http://calculator.services/',
              'doAddResponse',
              'calculatorServices.doAddResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
    }
}
  • Apex class: AsyncCalculatorSevices.cls:
//Generated by wsdl2apex

public class AsyncCalculatorServices {
    public class doDivideResponseFuture extends System.WebServiceCalloutFuture {
        public Double getValue() {
            calculatorServices.doDivideResponse response = (calculatorServices.doDivideResponse)System.WebServiceCallout.endInvoke(this);
            return response.return_x;
        }
    }
    public class doSubtractResponseFuture extends System.WebServiceCalloutFuture {
        public Double getValue() {
            calculatorServices.doSubtractResponse response = (calculatorServices.doSubtractResponse)System.WebServiceCallout.endInvoke(this);
            return response.return_x;
        }
    }
    public class doMultiplyResponseFuture extends System.WebServiceCalloutFuture {
        public Double getValue() {
            calculatorServices.doMultiplyResponse response = (calculatorServices.doMultiplyResponse)System.WebServiceCallout.endInvoke(this);
            return response.return_x;
        }
    }
    public class doAddResponseFuture extends System.WebServiceCalloutFuture {
        public Double getValue() {
            calculatorServices.doAddResponse response = (calculatorServices.doAddResponse)System.WebServiceCallout.endInvoke(this);
            return response.return_x;
        }
    }
    public class AsyncCalculatorImplPort {
        public String endpoint_x = 'https://th-apex-soap-service.herokuapp.com/service/calculator';
        public Map<String,String> inputHttpHeaders_x;
        public String clientCertName_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://calculator.services/', 'calculatorServices'};
        public AsyncCalculatorServices.doDivideResponseFuture beginDoDivide(System.Continuation continuation,Double arg0,Double arg1) {
            calculatorServices.doDivide request_x = new calculatorServices.doDivide();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            return (AsyncCalculatorServices.doDivideResponseFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncCalculatorServices.doDivideResponseFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doDivide',
              'http://calculator.services/',
              'doDivideResponse',
              'calculatorServices.doDivideResponse'}
            );
        }
        public AsyncCalculatorServices.doSubtractResponseFuture beginDoSubtract(System.Continuation continuation,Double arg0,Double arg1) {
            calculatorServices.doSubtract request_x = new calculatorServices.doSubtract();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            return (AsyncCalculatorServices.doSubtractResponseFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncCalculatorServices.doSubtractResponseFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doSubtract',
              'http://calculator.services/',
              'doSubtractResponse',
              'calculatorServices.doSubtractResponse'}
            );
        }
        public AsyncCalculatorServices.doMultiplyResponseFuture beginDoMultiply(System.Continuation continuation,Double arg0,Double arg1) {
            calculatorServices.doMultiply request_x = new calculatorServices.doMultiply();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            return (AsyncCalculatorServices.doMultiplyResponseFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncCalculatorServices.doMultiplyResponseFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doMultiply',
              'http://calculator.services/',
              'doMultiplyResponse',
              'calculatorServices.doMultiplyResponse'}
            );
        }
        public AsyncCalculatorServices.doAddResponseFuture beginDoAdd(System.Continuation continuation,Double arg0,Double arg1) {
            calculatorServices.doAdd request_x = new calculatorServices.doAdd();
            request_x.arg0 = arg0;
            request_x.arg1 = arg1;
            return (AsyncCalculatorServices.doAddResponseFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncCalculatorServices.doAddResponseFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://calculator.services/',
              'doAdd',
              'http://calculator.services/',
              'doAddResponse',
              'calculatorServices.doAddResponse'}
            );
        }
    }
}

Well, that's all for now. Content will be updated regularly. Thanks for reading!

Post was published on , last updated on .

Like the content? Support the author by paypal.me!