Publishing Platform Events using SoapUI

Here lets us discuss how to publish the Salesforce platform events using the SoapUI.Use platform events to deliver secure and scalable custom notifications within Salesforce or from external sources. Platform events are part of Salesforce’s enterprise messaging platform. The platform provides an event-driven messaging architecture to enable apps to communicate inside and outside of Salesforce. Here is the simple platform event object 

1. Get  Enterprise WSDL

Here we’re using the enterprise WSDL to explore SOAP API. To get the WSDL, from Setup, enter API in the Quick Find box, then select API. On the API WSDL page, click Generate Enterprise WSDL.save the WSDL file to the local repository.

2. Create a Project in SoapUI 

File menu, select New SOAP Project and create a new project as shown below.

3. Get SessionId

In SoapUI, scroll down to the login operation. Expand it, and then double-click Request 1. A sample SOAP login request appears.

here is the soapUI request you need to send it as part of the request. after successfully login request, you will get the session id and instance URL.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
     
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>USER_NAME</urn:username>
         <urn:password>PW+TOKEN</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

4. Create a Platform Event 

now use create operation to create a platform event as shown below

Here is the sample request that will be used to create a salesforce platform event. once you execute the request you will return the response with the platform event id

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:enterprise.soap.sforce.com" 
xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>00D1U000000q3IE!ARIAQFyc1O8jSygkdsqHCwFZVXaSNRw0HT.yFflnZ7u5A6IJjZXJUGwhBUBpwUfPZci1a0weLhHqwyL1ZBEBThzncLfKiyct</urn:sessionId>
      </urn:SessionHeader>
     
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <!--Zero or more repetitions:-->
         <urn:sObjects xsi:type="Shipments__e" 
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<urn:fieldsToNull xsi:nil="true"/>
			<urn:Id xsi:nil="true"/>
			<Shipment_Number__c>2131212360110</Shipment_Number__c>
			<Delivered__c>true</Delivered__c>
			<Invoice_Number__c>2131211213600</Invoice_Number__c>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

5.Subscribe to platform events 

Here is the simple trigger that will subscribe to platform events and create a simple task to the user.

trigger Subscribe on Shipments__e (after insert) {
    List<Task> tasks = new List<Task>();
    for (Shipments__e event : Trigger.New) {
        if (event.Delivered__c == true) {
            Task t = new Task();
            t.Priority = 'Medium';
            t.ActivityDate= System.today()+10;
            t.Subject = 'Follow up on shipped order ' + event.Shipment_Number__c;
            t.OwnerId = UserInfo.getUserId();
            tasks.add(t);
            
        }
    }
    if (tasks.size() > 0) {
        insert tasks;
    }
}