MuleSoft

How To Send Alerts Using The Create Notification Feature

Introduction

  • This blog will contain the steps that are necessary for creating a custom notification.
  • To demonstrate this, I’ll be going with a usecase where I’ll be fetching the data from the Salesforce custom object and how we can create a notification to send an alert in case of a scenario where Salesforce might fail.

Pre-requisites

  • We need to have an active Anypoint platform account as well as Anypoint Studio should be set up.
  • We need to have a Salesforce developer account.
  • Create a Salesforce custom object with some fields, as per the requirement.
  • Click on Create in the home section, which is on the right-hand side. Then click on a custom object, then fill in the name of the custom object. Then click on fields and relationship, then select the fields with the respective type of information.
  • In this scenario, we’ll be having 4 fields i.e. Age c, Id c, JobRole c, Name  c. Age and ID fields have Number as the type of information whereas JobRole and Name fields have Text as the type of information stored in them.
  • We need to keep the security token handy for that, click on profile and then click on setting which is on the right-hand top corner of the screen and type security token in the quick find section, and click on reset security token.
  • The security token will be sent to the registered mailId.

How to Send Alerts Using the Create Notification Feature

  • The CloudHub Connector in MuleSoft’s Anypoint Platform is used for integrating applications and services with CloudHub.
  • This connector provides operations:
    • List Notifications.
    • Create Notifications.
    • Get Application.
    • List Applications.
    • Mark Notification.
  • List notification is used to list the notifications of a mule application that is deployed on CloudHub.
  • Create notification is used to create notifications for the mule applications.
  • List application will list all the applications that are deployed to CloudHub in a specific environment.
  • Get application is used to get the info of the particular application deployed to CloudHub.
  • Mark notification will mark the notification as read or unread.
  • In this blog, we will see how to use a create Notification to create a notification and send an email alert for that. This can be commonly used when we need to create a notification for the error that occurred in the flow in the runtime manager.

Steps:

  1. First, we must create a new Mule Project and drag and drop a listener with HTTP configuration as well as the path mentioned for triggering the flow.

2. Following the addition of the Listener, include two loggers to mark the beginning and the end of the flow. By logging the message as “Start of flow” ++ (flow.name as String), in expression mode.

3. Then we need to add an Is Number validation component to validate the ID, whether it is a double type or not.

4. Then we need to add a query component and afterwards, we’ll add a query component and configure it.

5. Now we’ll configure the SOQL query and parameters. Here, in order to get an error from the salesforce query component the query that is written is not proper.

6. Now we’ll add a transform message to transform the data into JSON format.

7. Now we’ll add a logger to log the payload.

8. Now we’ll be configuring the error handling part. We’ll place an on error and continue to handle the error gracefully and the type will be set to ANY.

9. Now we need to add a set payload for creating the message for notification. The message should be in the string format as the message format that is accepted by the create notification is a string.

10. Now we’ll add a create notification component in the global element section and will be configuring it using Basic Authentication. We need to provide the username, and password of the Anypoint platform and environment name.

11. We need to configure the general section of the create notification where the domain is the name of the application for which we have to create a notification. For this instance, we’ll be creating a notification for this application itself so we’ll be writing the same name in the domain by which, the application will be deployed.

12. Message will be the payload which is created in set payload. We’ll be setting the priority as we want to notify the error caused during the execution and Transaction Id as uuid ().

13. Now we have to deploy the application to CloudHub and while deploying to the CloudHub, we need to name the application with the same name which we configured in the domain.

14. Once the application is deployed, then we’ll create an Alert having the condition as Custom application notification where priority is set as error and contains is failing component, for the application. We need to configure the recipients with the email address to which the alert has to be sent.

15. Once the application is up and running then we’ll hit the request by using Postman and as we can see in the image below, we’ll get an error that will be sent as notification.

16. We’ll verify by making use of Gmail which we configured as recipients in alerts.

Author

Aniket Pal

Leave a comment

Your email address will not be published. Required fields are marked *