Salesforce: Salesforce and Mulesoft Integration with Platform Event

 As we know salesforce have launched platform event to publish and subscribe channels for the integration.

Here will see how can we publish an event from Salesforce to Mulesoft.

Let's begin.......

Step1-Create a Platform Event as Cloud News.


Step2- Create 3 custom fields Location__c,News_Content__c and Urgent__c.


Step3-Download Mulesoft Anypoint Platform for 30 days free trial.
Step4-Create new mule project.
Step5-Add Subscribe channel listener from Mule Palette to Canvas.

Step6-Configure Salesforce Credentials as below.
    
    Provide username and password. If you have security token then please provide. 

Step7-Provide Streaming channel name as /event/Cloud_News__e. Note /event/ is used for platform event and /data/ is used for change data capture.

Step8-Add logger as below screenshot. Set message as #[payload. payload will display all attributes which event is publishing.

Step9-Save the project and run.
Step10-Create/Publish Cloud_News__e using Process Builder/Apex Class/API/Anonymous code. Below is the example.
Cloud_News__e newsEvent = new Cloud_News__e(Location__c = 'Bangalore',Urgent__c = true, 
           News_Content__c='MG Road Metro Station');
// publish events
EventBus.publish(newsEvent);

Step11-Check logs in Anypoint after running the above code.
INFO  2021-08-16 07:46:53,278 [[MuleRuntime].uber.05: [salesforceplatformintegration].salesforceplatformintegrationFlow.CPU_LITE @15673c5a] [processor: salesforceplatformintegrationFlow/processors/0; event: cbbf81c0-fea0-11eb-b8f1-76d83eb84c96] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: {data={schema=eGRz2Sfoy-YO9mVvH8J4fg, payload={News_Content__c=MG Road Metro Station, CreatedById=0052v00000fNDNzAAO, CreatedDate=2021-08-16T14:46:51.625Z, Location__c=Bangalore, Urgent__c=true}, event={replayId=2748588}}, channel=/event/Cloud_News__e}

Happy Learning!!

Comments