“What if our development team gets notified each time a case is created in the Support Org?” A thought that struck my colleague Deepak eventually became the spark for building and implementing a HipChat Notifier app within Salesforce. As the name suggests, the purpose of the App was simple – to notify our development team whenever a case has been created in the Dazeworks Support org. To give you a bit of background into that; the Dazeworks Support org is where, you as a Dazeworks client can log cases related to any issue that may crop up in a proj A world without the HipChat Notifier app involved the dev team keeping track of their emails or the org to know if a case is created. With this app in place, even if you are neck-deep in work, you would get a notification as and when a case is logged. And you’ll have to try really hard to not notice that, even if you had wanted to! So, this was just what we needed for a busy day at work!
The App which was implemented in the Salesforce platform, has been built with the following technologies:
- HipChat APIs – Big thanks to HipChat for providing us with such simple APIs!
For achieving this, an Apex Trigger was created to make API calls to HipChat whenever a case is logged in the org.
HipChat Notifier Flowchart
Fig 1.1: Flowchart
Before beginning to implement this in Salesforce, there are a few initial settings that need to be configured in HipChat. These include selecting the specific HipCHat room into which the notifications have to be pushed and building our own integration. Firstly, log into the web interface of HipChat and then follow the screenshots shown below.
Note: You will need Administrator Permissions to set this up.
Fig 1.2: Step 1
Fig 1.3: Step 2
Fig 1.4: Step 3
Creating a Custom Setting in Salesforce
Once HipChat is configured, we can move to Salesforce and make a Custom Setting named ‘HipChat API Setting’ which contains a record for storing HipChat endpoint. The HTTP request to HipChat servers is made using this endpoint. Endpoint is a location in the server to which a request has to be made. The authentication here is done with the Access Token which we received with the endpoint.
Creating the Remote Site
A new remote site named ‘Hip_Chat ‘ was created with ‘https://dazeworks.hipchat.com’ as the value.
Creating the Trigger
After setting up the endpoint, an ‘after Insert’ trigger was created which would fire each time a case is logged. Within the trigger, we also call a method within a class named HipChatNotifier and pass a custom message as parameter which states ‘New Case has been created‘. It can even say ‘Mayday, Mayday’ if you’d like it to! 🙂
Case Trigger :
Generating the Notification
The class HipChatNotifier accepts the custom message as its parameter. It also grabs the endpoint from the custom settings and constructs the body which is of type JSON and appends our custom message to “message:” token in the body. We can also change the background colour of the notification created by changing the value of “color”. It then makes a POST request to the HipChat Servers and gets the Response. On receiving a Status of 201, a notification appears in the respective group in HipChat.
HipChat Notifier Class :
Fig 1.5: Notification in HipChat
See how easy that was? The really cool integration capabilities of Salesforce along with the HipChat APIs allow users to do nearly anything and everything. If you have a similar story to share, do let us know in the comments section below.