Piggibacking Platform Events, Igor Chtivelband

CzechDreamin
CzechDreaminCzechDreamin
Piggybacking Platform Events
or “How we crack nuts with the Great
Seal of England”
by Igor Chtivelband
!1
#CD19
B.Sc. in Information Systems
Engineering
Double M.Sc. in Software
Engineering
Certified System and Application
Architect
VP Data at
!2
#CD19
Event-driven architecture basics
!3
#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
#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
#CD19
MessageForAdmin__e: Event Definition
!6
#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
#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
#CD19
ContactOrLeadEmailRequest__e: Definition
!9
#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
#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
#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
Thank you!
!13
1 of 13

Recommended

Employee management system report by
Employee management system reportEmployee management system report
Employee management system reportPrince Singh
15.9K views31 slides
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar... by
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...ITCamp
1.6K views32 slides
Training thethings.iO by
Training thethings.iOTraining thethings.iO
Training thethings.iOMarc Pous
496 views65 slides
Exchange Integration by
Exchange IntegrationExchange Integration
Exchange IntegrationConnecting Software
69 views2 slides
Creating Single Page Applications with Oracle Apex by
Creating Single Page Applications with Oracle ApexCreating Single Page Applications with Oracle Apex
Creating Single Page Applications with Oracle ApexDick Dral
3.5K views39 slides
Spawithapex0 150815075436-lva1-app6891 by
Spawithapex0 150815075436-lva1-app6891Spawithapex0 150815075436-lva1-app6891
Spawithapex0 150815075436-lva1-app6891Mohamedcpcbma
42 views39 slides

More Related Content

Similar to Piggibacking Platform Events, Igor Chtivelband

Platform Events by Tim Taylor by
Platform Events by Tim TaylorPlatform Events by Tim Taylor
Platform Events by Tim TaylorChristine Smith
598 views19 slides
Aug Xml Net Forum Dynamics Integration by
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationMariAnne Woehrle
408 views36 slides
IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2 by
IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2
IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2jayeshpar2006
3.5K views30 slides
FO Automation Platform by
FO Automation Platform  FO Automation Platform
FO Automation Platform Nhật An Đinh
577 views26 slides
S-Controls for Dummies by
S-Controls for DummiesS-Controls for Dummies
S-Controls for Dummiesdreamforce2006
2.2K views38 slides
S-Controls for Dummies by
S-Controls for DummiesS-Controls for Dummies
S-Controls for Dummiesdreamforce2006
5.2K views38 slides

Similar to Piggibacking Platform Events, Igor Chtivelband(20)

Aug Xml Net Forum Dynamics Integration by MariAnne Woehrle
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
MariAnne Woehrle408 views
IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2 by jayeshpar2006
IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2
IBM Notes Traveler Administration and Log Troubleshooting tips - Part 2
jayeshpar20063.5K views
Gui application for e mail application by Umesh Mk
Gui application for e mail applicationGui application for e mail application
Gui application for e mail application
Umesh Mk118 views
Recharge_report_Automation by KIIT
Recharge_report_AutomationRecharge_report_Automation
Recharge_report_Automation
KIIT255 views
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c by Gokhan Atil
Using APEX to Create a Mobile User Interface for Enterprise Manager 12cUsing APEX to Create a Mobile User Interface for Enterprise Manager 12c
Using APEX to Create a Mobile User Interface for Enterprise Manager 12c
Gokhan Atil2.4K views
E Governance Design & Implementation by ncct
E Governance Design & ImplementationE Governance Design & Implementation
E Governance Design & Implementation
ncct172 views
Evolutionary db development by Open Party
Evolutionary db development Evolutionary db development
Evolutionary db development
Open Party460 views
Getting started with the Enterprise Mobility Suite (EMS) by Ronni Pedersen
Getting started with the Enterprise Mobility Suite (EMS)Getting started with the Enterprise Mobility Suite (EMS)
Getting started with the Enterprise Mobility Suite (EMS)
Ronni Pedersen3.6K views
SAP E-Document (Mexico) by Surya Padhi
SAP E-Document (Mexico) SAP E-Document (Mexico)
SAP E-Document (Mexico)
Surya Padhi3K views
A Novel Secure Cloud SAAS Integration for User Authenticated Information by ijtsrd
A Novel Secure Cloud SAAS Integration for User Authenticated InformationA Novel Secure Cloud SAAS Integration for User Authenticated Information
A Novel Secure Cloud SAAS Integration for User Authenticated Information
ijtsrd9 views
T3 dim 4.0 (flex dim) technical discussion by Chris Lee
T3 dim 4.0 (flex dim) technical discussionT3 dim 4.0 (flex dim) technical discussion
T3 dim 4.0 (flex dim) technical discussion
Chris Lee218 views

More from CzechDreamin

Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi... by
Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi...Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi...
Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi...CzechDreamin
1.1K views32 slides
Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ... by
Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ...Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ...
Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ...CzechDreamin
1K views27 slides
How we should include Devops Center to get happy developers?, David Fernandez... by
How we should include Devops Center to get happy developers?, David Fernandez...How we should include Devops Center to get happy developers?, David Fernandez...
How we should include Devops Center to get happy developers?, David Fernandez...CzechDreamin
1K views20 slides
Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G... by
Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G...Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G...
Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G...CzechDreamin
1K views18 slides
Architecting for Analytics, Aaron Crear by
Architecting for Analytics, Aaron CrearArchitecting for Analytics, Aaron Crear
Architecting for Analytics, Aaron CrearCzechDreamin
1.1K views16 slides
Ape to API, Filip Dousek by
Ape to API, Filip DousekApe to API, Filip Dousek
Ape to API, Filip DousekCzechDreamin
1.1K views32 slides

More from CzechDreamin(20)

Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi... by CzechDreamin
Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi...Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi...
Salesforce Forecasting: Evolution, Implementation and Best Practices, Christi...
CzechDreamin1.1K views
Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ... by CzechDreamin
Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ...Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ...
Supercharge Salesforce Marketing Cloud: The Ultimate Apps Guide, Cyril Louis ...
CzechDreamin1K views
How we should include Devops Center to get happy developers?, David Fernandez... by CzechDreamin
How we should include Devops Center to get happy developers?, David Fernandez...How we should include Devops Center to get happy developers?, David Fernandez...
How we should include Devops Center to get happy developers?, David Fernandez...
CzechDreamin1K views
Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G... by CzechDreamin
Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G...Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G...
Streamline Your Integration with Salesforce’s Composite API: A Consultant’s G...
CzechDreamin1K views
Architecting for Analytics, Aaron Crear by CzechDreamin
Architecting for Analytics, Aaron CrearArchitecting for Analytics, Aaron Crear
Architecting for Analytics, Aaron Crear
CzechDreamin1.1K views
Ape to API, Filip Dousek by CzechDreamin
Ape to API, Filip DousekApe to API, Filip Dousek
Ape to API, Filip Dousek
CzechDreamin1.1K views
How do you know you’re solving the right problem? Design Thinking for Salesfo... by CzechDreamin
How do you know you’re solving the right problem? Design Thinking for Salesfo...How do you know you’re solving the right problem? Design Thinking for Salesfo...
How do you know you’re solving the right problem? Design Thinking for Salesfo...
CzechDreamin1.1K views
Real-time communication with Account Engagement (Pardot). Marketers meet deve... by CzechDreamin
Real-time communication with Account Engagement (Pardot). Marketers meet deve...Real-time communication with Account Engagement (Pardot). Marketers meet deve...
Real-time communication with Account Engagement (Pardot). Marketers meet deve...
CzechDreamin1.1K views
Black Hat Session: Exploring and Exploiting Aura based Experiences, Christian... by CzechDreamin
Black Hat Session: Exploring and Exploiting Aura based Experiences, Christian...Black Hat Session: Exploring and Exploiting Aura based Experiences, Christian...
Black Hat Session: Exploring and Exploiting Aura based Experiences, Christian...
CzechDreamin1.2K views
5 key ideas for robust and flexible REST API integrations with Apex, Lucian M... by CzechDreamin
5 key ideas for robust and flexible REST API integrations with Apex, Lucian M...5 key ideas for robust and flexible REST API integrations with Apex, Lucian M...
5 key ideas for robust and flexible REST API integrations with Apex, Lucian M...
CzechDreamin1.1K views
Report & Dashboard REST API : Get your report accessible anywhere !, Romain Q... by CzechDreamin
Report & Dashboard REST API : Get your report accessible anywhere !, Romain Q...Report & Dashboard REST API : Get your report accessible anywhere !, Romain Q...
Report & Dashboard REST API : Get your report accessible anywhere !, Romain Q...
CzechDreamin1.1K views
No Such Thing as Best Practice in Design, Nati Asher and Pat Fragoso by CzechDreamin
No Such Thing as Best Practice in Design, Nati Asher and Pat FragosoNo Such Thing as Best Practice in Design, Nati Asher and Pat Fragoso
No Such Thing as Best Practice in Design, Nati Asher and Pat Fragoso
CzechDreamin1.2K views
Why do you Need to Migrate to Salesforce Flow?, Andrew Cook by CzechDreamin
Why do you Need to Migrate to Salesforce Flow?, Andrew CookWhy do you Need to Migrate to Salesforce Flow?, Andrew Cook
Why do you Need to Migrate to Salesforce Flow?, Andrew Cook
CzechDreamin1.1K views
Be kind to your future admin self, Silvia Denaro & Nathaniel Sombu by CzechDreamin
Be kind to your future admin self, Silvia Denaro & Nathaniel SombuBe kind to your future admin self, Silvia Denaro & Nathaniel Sombu
Be kind to your future admin self, Silvia Denaro & Nathaniel Sombu
CzechDreamin1.1K views
Monitoring Automation Performance in Marketing Cloud Engagement, Daniela Vrbk... by CzechDreamin
Monitoring Automation Performance in Marketing Cloud Engagement, Daniela Vrbk...Monitoring Automation Performance in Marketing Cloud Engagement, Daniela Vrbk...
Monitoring Automation Performance in Marketing Cloud Engagement, Daniela Vrbk...
CzechDreamin1.2K views
The minimum-profile approach – the modern way to design an efficient security... by CzechDreamin
The minimum-profile approach – the modern way to design an efficient security...The minimum-profile approach – the modern way to design an efficient security...
The minimum-profile approach – the modern way to design an efficient security...
CzechDreamin1.2K views
Restriction Rules – The Whole Picture, Louise Lockie by CzechDreamin
Restriction Rules – The Whole Picture, Louise LockieRestriction Rules – The Whole Picture, Louise Lockie
Restriction Rules – The Whole Picture, Louise Lockie
CzechDreamin1.5K views
Introduction to Custom Journey Builder Activities, Orkhan Alakbarli by CzechDreamin
Introduction to Custom Journey Builder Activities, Orkhan AlakbarliIntroduction to Custom Journey Builder Activities, Orkhan Alakbarli
Introduction to Custom Journey Builder Activities, Orkhan Alakbarli
CzechDreamin1.2K views
Taking control of your queries with GraphQL, Alba Rivas by CzechDreamin
Taking control of your queries with GraphQL, Alba RivasTaking control of your queries with GraphQL, Alba Rivas
Taking control of your queries with GraphQL, Alba Rivas
CzechDreamin1.2K views
“Soft Skills” are the new “Hard Skills” – Tips & Tricks for Salesforce Projec... by CzechDreamin
“Soft Skills” are the new “Hard Skills” – Tips & Tricks for Salesforce Projec...“Soft Skills” are the new “Hard Skills” – Tips & Tricks for Salesforce Projec...
“Soft Skills” are the new “Hard Skills” – Tips & Tricks for Salesforce Projec...
CzechDreamin1.1K views

Recently uploaded

Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...ShapeBlue
74 views17 slides
"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
49 views29 slides
Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
76 views26 slides
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...ShapeBlue
113 views18 slides
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
142 views32 slides
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...ShapeBlue
52 views10 slides

Recently uploaded(20)

Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue74 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays49 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely76 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue113 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson142 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue52 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue69 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue154 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10110 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue121 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue172 views
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue58 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty54 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue110 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue114 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE67 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue56 views

Piggibacking Platform Events, Igor Chtivelband

  • 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
  • 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
  • 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
  • 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