Wednesday, April 20, 2022

Considerations for using Platform Events

Platform really helps in setting up custom notifications within salesforce or for external system. While utilising the platform events in salesforce, you need to consider below things:

  • Record Owner considerations

Whenever you create record from after insert using triggers, then ownerid of those records will be Automated Process by default. If you have set current user as record owner, then specify ownerid of created records as createdbyId of event.

Account acc= new Account(name='test account through Demo platform event',OwnerId = event.createdById);

  • Platform Event Trigger do not provide Email Support
As automated process user does not have email address, sending an email message from a platform event trigger using the Messaging.SingleEmailMessage class is not supported. As a workaround, send emails via email alert where the From Email Address is NOT "Current User's Email Address" but rather some other organization-wide email or default workflow user. 

In Apex, use the SingleEmailMessage.setOrgWideEmailAddressId method to set the org-wide email. 

Hope this will help!!