Piggibacking Platform Events, Igor Chtivelband

Information about Piggibacking Platform Events, Igor Chtivelband

Published on August 28, 2019

Author: CzechDreamin

Source: slideshare.net

Content

1. Piggybacking Platform Events or “How we crack nuts with the Great Seal of England” by Igor Chtivelband !1

2. #CD19 B.Sc. in Information Systems Engineering Double M.Sc. in Software Engineering Certified System and Application Architect VP Data at !2

3. #CD19 Event-driven architecture basics !3

4. #CD19 - First introduced in November 2017 - One can define a new Platform Event similarly to the way it is done with Custom Objects - Platform Events can be published using Apex, Declarative Tools (Process Builder/Flow) and API - Platform Events can be subscribed to using Apex Triggers, Process Builders and CometD Platform Events in Salesforce !4

5. #CD19 - Mainly we love them, because Platform Events help us to overcome transaction limits - We use them to inform Admins in case of exceptions/issues (MessageForAdmin__e) - We dispatch thousands of emails (some of them with custom attachments) in a couple of clicks (ContactOrLeadEmailRequest__e) - In case that a record is currently locked, we can update it asynchronously using a custom Platform Event So how exactly do we piggyback Platform Events in Billie? !5

6. #CD19 MessageForAdmin__e: Event Definition !6

7. #CD19 catch (Exception e){ MessageForAdmin__e m = new MessageForAdmin__e (); m.Subject__c = 'Bad news: tried to send email, but could not find Attachment'; m.Body__c = e.getMessage(); EventBus.publish(m); } MessageForAdmin__e: Publishing !7

8. #CD19 - Easy to send a notification from Apex code/process - Even if the main transaction is rolled-back, admins will still be notified - Since event publishing is decoupled from event consumption, we can always change the way the notifications are delivered (email, Slack, etc.) MessageForAdmin__e: advantages !8

9. #CD19 ContactOrLeadEmailRequest__e: Definition !9

10. #CD19 String ATTACHMENT_NAME_TEMPLATE = '2019-02-%_Billie_Invoice.pdf'; String EMAIL_TEMPLATE = 'Contact_Monthly_FeeInvoice'; List<ContactOrLeadEmailRequest__e> events = new List<ContactOrLeadEmailRequest__e>(); for (Attachment att: [SELECT parentId,Name FROM Attachment WHERE Name like :ATTACHMENT_NAME_TEMPLATE]){ events.add( new ContactOrLeadEmailRequest__e ( ObjectID__c = att.parentId, EmailTemplateName__c = EMAIL_TEMPLATE, AttachmentNamePattern__c = att.Name ) ); } List<Database.SaveResult> results = EventBus.publish(events); ContactOrLeadEmailRequest__e: Publishing !10

11. #CD19 - Limit of 100 emails per transaction is worked around - We can send mass emails with individual attachments (currently not supported by Salesforce “out of the box”) - No need to configure Email Alert - Email Messages are stored in Salesforce database and can be used for later analysis ContactOrLeadEmailRequest__e: advantages !11

12. #CD19 - Each EventBus.publish method call is considered a DML statement, and DML limits apply - Each EventBus.publish method call is considered an API call - If you are trying to publish Platform Events from an external system, you have to perform Oauth authentication - It is impossible to replay Platform Events from Apex - You can’t call Messaging.SingleEmailMessage methods directly in your event trigger Considerations for Publishing and Subscribing to Platform Events !12

13. Thank you! !13

#cd19 presentations

Czechitas, Ondřej Čejka
28. 08. 2019
0 views

Czechitas, Ondřej Čejka

Related presentations


Other presentations created by CzechDreamin

Czechitas, Ondřej Čejka
28. 08. 2019
0 views

Czechitas, Ondřej Čejka