We are sending an email message from custom LWC component embedded in a record detail page in Salesforce. When the recipient replies to that email, the reply comes to Salesforce through email service and we further forward that email to certain users and create activities etc. on the object from which this email was sent. When such an email is received, we want to show pop up to user so that he is notified upfront instead of refreshing the record detail page and checking if activity is created for the inbound email. Is this achievable in Salesforce?
2 Answers
You can try firing a Platform Event using the email service apex class and listen to that event using lightning-emp-api in LWC. You can then show a toast message once the event is heard.
Since you are anyways creating an activity, you can also explore using PushTopics instead of Platform events (Depending on the current limits you have in your org).
Check out the documentation for limits before choosing an approach:
Another approach to this requirement would be to use Custom Notifications as explained in this answer. In the InboundEmailHandler class, we would make the call to throw the custom notification as explained in above link. We have to create a custom notification type and use it in this call from this InboundEmailHandler.
This way we need not implement a LWC component and throw toast, configure it etc. This will show notification standard way in the bell icon on top of page and also will persist across apps (including settings). Advantage of this is also that we need not maintain state of notifications (read/unread) in case page is manually refreshed or navigated away to some other app.
Ended up implementing this approach for above requirement.