SlideShare a Scribd company logo
1 of 32
Ghulam Mohayyudin
6x Certified Salesforce Developer at TEKHQS
mohayyudinuaf@gmail.com
Agenda
What I Will Share
● What is Platform Event
● Architecture of event driven software
● What is Salesforce Platform Event
● Ways To Publish Salesforce Platform Event
● Ways To Subscribe Salesforce Platform Events
● Real time use case of Platform Events
● Demo
What is Platform Event
● Platform events are secure and scalable messages that contain data
● Use platform events to connect business processes in Salesforce and
external apps through the exchange of real-time event data
● Publishers publish event messages that subscribers receive in real time
● To customize the data published, define platform event fields
What is an Event-Driven Software Architecture?
● Consists of event producers, event consumers, and channels.
● Suitable for large distributed systems
● Decouples event producers from the event consumers.
● Components:
○ Producer: publisher of the event message over channel
○ Consumer: subscribes to a channel to receive
○ Event: change in state meaningful to business
○ Event Message: data about the event
○ Event Bus Or Channel: The event gets added onto the event bus (aka
channel), which operates as a queue, with a strict chronological order,
and executes each event one after the other.
What is an Event-Driven Software Architecture?
Event-Driven Software Architecture Components
Salesforce Platform Events
● Platform events are messages that are
published and subscribed to.
● One or more subscribers can listen to the
same event and carry out independent
actions.
● This way, key components of an integration
are decoupled.
● Define a custom event in same way as
custom objects.
● Create the event by giving it a name and
adding custom fields.
Ways To Publish Salesforce Platform Event
● Publish Event Using Apex
○ To publish event messages by Apex, call the EventBus.publish() method passing an instance of the custom event.
trigger CaseEventTrigger on Case(before insert) {
List < Demo_Custom_Event__e > registrationEvents = new List < Demo_Custom_Event__e > ();
for (Case c: Trigger.New) {
if (Trigger.oldMap.get(c.Id).Status != C.Status) {
registrationEvents.add(new Notifiy_Custom_Event__e(CaseId__c = c.Id));
}
if (!registrationEvents.isEmpty()) EventBus.publish(registrationEvents);
}
}
Ways To Publish Salesforce Platform Event
● API Published Events
○ External applications use an API to publish event messages.
○ You can use any Salesforce API to create events in same way as you
would insert sObjects.
● REST endpoint:
/services/data/v47.0/sobjects/Registration_Notification_e
● Request body:
{
"CaseId__c": "5005j00000mUQUvAAO”,
“Jirra_Status__c” : “High Periority”
}
● REST response:
{
"id": "e00xx0000000001AAA",
"success": true,
"errors": [
{
"statusCode": "OPERATION_ENQUEUED",
"message": "411c1c7c-51cd-4595-b45a-c12b32e799c9",
"fields": []
}
]
}
Ways To Subscribe Salesforce Platform Events
● Subscribing to Events with Apex Triggers
○ Triggers provide an auto subscription mechanism in Apex. No need to explicitly create and listen to a channel.
○ Platform events ONLY support after insert
trigger EventRegisterTrigger on Demo_Event__e (after insert) {
List <Demo_Event__e> eventsReceived = new List <Demo_Event__e> ();
for (Demo_Event__e event: Trigger.New) {
eventsReceived.add(event);
}
List<Case> casesToUpdate = new List<Case>();
if (eventsReceived.size() > 0){
for(Demo_Event__e event: eventsReceived){
case cas = new case();
cas.Id = event.CaseId__c;
cas.Status = event.Jirra_Status__c ;
casesToUpdate.add(cas);
}
upsert casesToUpdate;
system.debug('Event listened successfully');
}
}
Ways To Subscribe Salesforce Platform Events
● Subscribing to Events with
Salesforce Flow Builder
○ Flow also provide an auto subscription
mechanism for published events. No need to
explicitly create and listen to a channel.
○ To subscribe to a platform event, create flow
with template Platform Event-Triggered Flow
to start when it receives an event message.
● Subscribing to Events with CometD
○ External systems can subscribe to platform
events using CometD
○ The entities that consume platform events
should subscribe to the event's channel.
Ways To Subscribe Salesforce Platform Events
● Subscribing to Events with Lightning Components
○ Subscribe to platform events with empApi component
○ In Lightning Web components import the methods from the lightning/empApi module and then call the imported methods from your javascript code.
○ In Aura components add the lightning:empApi component in your markup and then add functions to call the component methods in your client-side controller.
● Lightning Web Component:
○ Import < subscribe, unsubscribe, onError, } from lightning/empApi;
● Lightning Aura Component:
○ <lightning:empApi aura:id="empApi" />
DoInIt: function(component, event, helper) {
var channel = '/event/EbizC__Batch_Job_Finished_Event__e';
const replayId = -1;
const empApi = component.find("empApi");
const callback = function (message) {
var messageInfo = message.data.payload;
Console.log(‘CaseId >>> ’+messageInfo.CaseId__c);
};
empApi.subscribe(channel, replayId, callback).then(function(newSubscription) {
});
const errorHandler = function (message) {
console.error("Received error ", JSON.stringify(message));
};
empApi.onError(errorHandler);
}
Platform Events Considerations
● Platform event is appended with _e suffix for API name of the event.
● You can not query Platform events through SOQL or SOSL.
● You can not use Platform in reports, list views, and search.
● Platform events don't have an associated tab.
● Published platform events can't be rolled back.
● All platform event fields are read-only by default.
● Only after insert Triggers Are Supported.
● You can access platform events both through API and declaratively.
● You can control platform events though Profiles and permissions.
References
● https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_intro.htm
● https://www.salesforceben.com/salesforce-platform-events/
● https://trailhead.salesforce.com/content/learn/modules/platform_events_basics
● https://www.slideshare.net/ChristineSmith33/platform-events-by-tim-taylor
● https://www.youtube.com/playlist?list=PLFe2L4qdtVpZl3TDEtPE6L023ZoZSx1EY
Ghulam Ghaus
4x Certified Salesforce Developer at Logic Mount
g.ghaus001@gmail.com
Agenda
What I Will Share
● What is Apex Replay Debugger
● Key Features
● How does it work?
● Best Practices for Effective Debugging
● Live Demo in Visual Studio Code
What is Apex Replay Debugger
● Apex Replay Debugger is a free tool that allows us to debug the Apex code
by inspecting debug logs using Visual Studio Code
● We can view variables, set checkpoints, and hover over variables to see their
current value
● We no longer need to parse through thousands of log lines manually or
sprinkle your code with System.debug statements to see variable values or
track the code execution path.
Key Features
● Real-time debugging
● Step-by-step execution
● Variable inspection
How does it work?
● Setting checkpoints in the code
● Run Apex and Get Debug Logs
● Replay of code execution from checkpoints
● Real-time inspection of variables Step-by-step execution
and analysis
Setting Check Points in the code
● In Visual Studio Code, open the apex class or
trigger you want to debug file and focus the
cursor on the line where you want to set up
the check point.
● Click the View menu then choose Command
Palette.... Alternatively, we can use the
keyboard shortcut Ctrl+Shift+P (Windows or
Linux) or Cmd+Shift+P (macOS) to open the
Command Palette.
● Enter sfdx checkpoint in the search box, then
choose SFDX: Toggle Checkpoint.
Setting Check Points in the code
● We can see an indicator next to the line
number showing that the checkpoint
was set.
● Open the Command Palette and enter sfdx
checkpoint in the search box, then choose
SFDX: Update Checkpoints in Org.
Run Apex and Get Debug Logs
● With our breakpoints and checkpoints set, it’s time
to rerun our Apex test to generate a replay-
enabled debug log.
● Run the Apex Code
● In Visual Studio Code,use the keyboard shortcut Ctrl+Shift+P
(Windows or Linux) or Cmd+Shift+P (macOS) to open the
Command Palette.
● se SFDX: Turn On Apex Debug Log for Replay Debugger. This
creates a trace flag to generate replay-enabled debug logs for
30 minutes. You can change the duration in Setup on the
Debug Logs page.
Run Apex and Get Debug Logs
● After code execution, Open the Command Palette
and enter sfdx get in the search box, then choose
SFDX: Get Apex Debug Logs
● Choose the debug log associated with the recent
Apex Run
● Click Continue button on Debug Toolbar on the Debug
Toolbar to continue to the first breakpoint
● Right-click any line in the debug log, then choose
SFDX: Launch Apex Replay Debugger with
Current File
Run Apex and Get Debug Logs
● Benefits
● Faster issue resolution
● Improved code quality
● Time-saving
● Considerations
● Only one debug log at a time
● You can’t replay a debug log generated by scheduled Apex.
● We can’t expand a collection
● Best Practices for Effective Debugging
● Set meaningful checkpoints
● Use logging statements
● Practice regularly
● Live Demo in Visual Studio Code
● Walkthrough of setting checkpoints
● Initiating debugging sessions
● Stepping through code execution
● Inspecting variables
● Q&A
Any Questions?
Apex Replay Debugger and Salesforce Platform Events.pptx

More Related Content

Similar to Apex Replay Debugger and Salesforce Platform Events.pptx

Indianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptxIndianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptxikram_ahamed
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
M365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx VersionM365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx VersionThomas Daly
 
Extending WSO2 Analytics Platform
Extending WSO2 Analytics PlatformExtending WSO2 Analytics Platform
Extending WSO2 Analytics PlatformWSO2
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentalsAmit Sharma
 
Building Kick Ass Video Games for the Cloud
Building Kick Ass Video Games for the CloudBuilding Kick Ass Video Games for the Cloud
Building Kick Ass Video Games for the CloudChris Schalk
 
Lightning Components Explained
Lightning Components ExplainedLightning Components Explained
Lightning Components ExplainedAtul Gupta(8X)
 
Tool overview – how to capture – how to create basic workflow .pptx
Tool overview – how to capture – how to create basic workflow .pptxTool overview – how to capture – how to create basic workflow .pptx
Tool overview – how to capture – how to create basic workflow .pptxRUPAK BHATTACHARJEE
 
Qtp 9.2 examples
Qtp 9.2 examplesQtp 9.2 examples
Qtp 9.2 examplesmedsherb
 
Hands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comHands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comSalesforce Developers
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentalsAmit Sharma
 
ISV Error Handling With Spring '21 Update
ISV Error Handling With Spring '21 UpdateISV Error Handling With Spring '21 Update
ISV Error Handling With Spring '21 UpdateCodeScience
 
Anypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupAnypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupMergeStack
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andevMike Nakhimovich
 
Subscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-finalSubscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-finalSamuel Sharaf
 

Similar to Apex Replay Debugger and Salesforce Platform Events.pptx (20)

Indianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptxIndianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptx
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
M365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx VersionM365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx Version
 
Extending WSO2 Analytics Platform
Extending WSO2 Analytics PlatformExtending WSO2 Analytics Platform
Extending WSO2 Analytics Platform
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentals
 
Building Kick Ass Video Games for the Cloud
Building Kick Ass Video Games for the CloudBuilding Kick Ass Video Games for the Cloud
Building Kick Ass Video Games for the Cloud
 
Lightning Components Explained
Lightning Components ExplainedLightning Components Explained
Lightning Components Explained
 
Tool overview – how to capture – how to create basic workflow .pptx
Tool overview – how to capture – how to create basic workflow .pptxTool overview – how to capture – how to create basic workflow .pptx
Tool overview – how to capture – how to create basic workflow .pptx
 
Qtp 9.2 examples
Qtp 9.2 examplesQtp 9.2 examples
Qtp 9.2 examples
 
OneTeam Media Server
OneTeam Media ServerOneTeam Media Server
OneTeam Media Server
 
Hands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comHands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.com
 
Nexmark with beam
Nexmark with beamNexmark with beam
Nexmark with beam
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentals
 
Building a Slack Bot Workshop @ Nearsoft OctoberTalks 2017
Building a Slack Bot Workshop @ Nearsoft OctoberTalks 2017Building a Slack Bot Workshop @ Nearsoft OctoberTalks 2017
Building a Slack Bot Workshop @ Nearsoft OctoberTalks 2017
 
More than MOPS: Wall-to-Wall Automations
More than MOPS: Wall-to-Wall AutomationsMore than MOPS: Wall-to-Wall Automations
More than MOPS: Wall-to-Wall Automations
 
ISV Error Handling With Spring '21 Update
ISV Error Handling With Spring '21 UpdateISV Error Handling With Spring '21 Update
ISV Error Handling With Spring '21 Update
 
Flink. Pure Streaming
Flink. Pure StreamingFlink. Pure Streaming
Flink. Pure Streaming
 
Anypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupAnypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetup
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Subscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-finalSubscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-final
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingSelcen Ozturkcan
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Apex Replay Debugger and Salesforce Platform Events.pptx

  • 1.
  • 2.
  • 3. Ghulam Mohayyudin 6x Certified Salesforce Developer at TEKHQS mohayyudinuaf@gmail.com
  • 4. Agenda What I Will Share ● What is Platform Event ● Architecture of event driven software ● What is Salesforce Platform Event ● Ways To Publish Salesforce Platform Event ● Ways To Subscribe Salesforce Platform Events ● Real time use case of Platform Events ● Demo
  • 5. What is Platform Event ● Platform events are secure and scalable messages that contain data ● Use platform events to connect business processes in Salesforce and external apps through the exchange of real-time event data ● Publishers publish event messages that subscribers receive in real time ● To customize the data published, define platform event fields
  • 6. What is an Event-Driven Software Architecture? ● Consists of event producers, event consumers, and channels. ● Suitable for large distributed systems ● Decouples event producers from the event consumers. ● Components: ○ Producer: publisher of the event message over channel ○ Consumer: subscribes to a channel to receive ○ Event: change in state meaningful to business ○ Event Message: data about the event ○ Event Bus Or Channel: The event gets added onto the event bus (aka channel), which operates as a queue, with a strict chronological order, and executes each event one after the other.
  • 7. What is an Event-Driven Software Architecture?
  • 9. Salesforce Platform Events ● Platform events are messages that are published and subscribed to. ● One or more subscribers can listen to the same event and carry out independent actions. ● This way, key components of an integration are decoupled. ● Define a custom event in same way as custom objects. ● Create the event by giving it a name and adding custom fields.
  • 10. Ways To Publish Salesforce Platform Event ● Publish Event Using Apex ○ To publish event messages by Apex, call the EventBus.publish() method passing an instance of the custom event. trigger CaseEventTrigger on Case(before insert) { List < Demo_Custom_Event__e > registrationEvents = new List < Demo_Custom_Event__e > (); for (Case c: Trigger.New) { if (Trigger.oldMap.get(c.Id).Status != C.Status) { registrationEvents.add(new Notifiy_Custom_Event__e(CaseId__c = c.Id)); } if (!registrationEvents.isEmpty()) EventBus.publish(registrationEvents); } }
  • 11. Ways To Publish Salesforce Platform Event ● API Published Events ○ External applications use an API to publish event messages. ○ You can use any Salesforce API to create events in same way as you would insert sObjects. ● REST endpoint: /services/data/v47.0/sobjects/Registration_Notification_e ● Request body: { "CaseId__c": "5005j00000mUQUvAAO”, “Jirra_Status__c” : “High Periority” } ● REST response: { "id": "e00xx0000000001AAA", "success": true, "errors": [ { "statusCode": "OPERATION_ENQUEUED", "message": "411c1c7c-51cd-4595-b45a-c12b32e799c9", "fields": [] } ] }
  • 12. Ways To Subscribe Salesforce Platform Events ● Subscribing to Events with Apex Triggers ○ Triggers provide an auto subscription mechanism in Apex. No need to explicitly create and listen to a channel. ○ Platform events ONLY support after insert trigger EventRegisterTrigger on Demo_Event__e (after insert) { List <Demo_Event__e> eventsReceived = new List <Demo_Event__e> (); for (Demo_Event__e event: Trigger.New) { eventsReceived.add(event); } List<Case> casesToUpdate = new List<Case>(); if (eventsReceived.size() > 0){ for(Demo_Event__e event: eventsReceived){ case cas = new case(); cas.Id = event.CaseId__c; cas.Status = event.Jirra_Status__c ; casesToUpdate.add(cas); } upsert casesToUpdate; system.debug('Event listened successfully'); } }
  • 13. Ways To Subscribe Salesforce Platform Events ● Subscribing to Events with Salesforce Flow Builder ○ Flow also provide an auto subscription mechanism for published events. No need to explicitly create and listen to a channel. ○ To subscribe to a platform event, create flow with template Platform Event-Triggered Flow to start when it receives an event message. ● Subscribing to Events with CometD ○ External systems can subscribe to platform events using CometD ○ The entities that consume platform events should subscribe to the event's channel.
  • 14. Ways To Subscribe Salesforce Platform Events ● Subscribing to Events with Lightning Components ○ Subscribe to platform events with empApi component ○ In Lightning Web components import the methods from the lightning/empApi module and then call the imported methods from your javascript code. ○ In Aura components add the lightning:empApi component in your markup and then add functions to call the component methods in your client-side controller. ● Lightning Web Component: ○ Import < subscribe, unsubscribe, onError, } from lightning/empApi; ● Lightning Aura Component: ○ <lightning:empApi aura:id="empApi" /> DoInIt: function(component, event, helper) { var channel = '/event/EbizC__Batch_Job_Finished_Event__e'; const replayId = -1; const empApi = component.find("empApi"); const callback = function (message) { var messageInfo = message.data.payload; Console.log(‘CaseId >>> ’+messageInfo.CaseId__c); }; empApi.subscribe(channel, replayId, callback).then(function(newSubscription) { }); const errorHandler = function (message) { console.error("Received error ", JSON.stringify(message)); }; empApi.onError(errorHandler); }
  • 15. Platform Events Considerations ● Platform event is appended with _e suffix for API name of the event. ● You can not query Platform events through SOQL or SOSL. ● You can not use Platform in reports, list views, and search. ● Platform events don't have an associated tab. ● Published platform events can't be rolled back. ● All platform event fields are read-only by default. ● Only after insert Triggers Are Supported. ● You can access platform events both through API and declaratively. ● You can control platform events though Profiles and permissions.
  • 16. References ● https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_intro.htm ● https://www.salesforceben.com/salesforce-platform-events/ ● https://trailhead.salesforce.com/content/learn/modules/platform_events_basics ● https://www.slideshare.net/ChristineSmith33/platform-events-by-tim-taylor ● https://www.youtube.com/playlist?list=PLFe2L4qdtVpZl3TDEtPE6L023ZoZSx1EY
  • 17. Ghulam Ghaus 4x Certified Salesforce Developer at Logic Mount g.ghaus001@gmail.com
  • 18. Agenda What I Will Share ● What is Apex Replay Debugger ● Key Features ● How does it work? ● Best Practices for Effective Debugging ● Live Demo in Visual Studio Code
  • 19. What is Apex Replay Debugger ● Apex Replay Debugger is a free tool that allows us to debug the Apex code by inspecting debug logs using Visual Studio Code ● We can view variables, set checkpoints, and hover over variables to see their current value ● We no longer need to parse through thousands of log lines manually or sprinkle your code with System.debug statements to see variable values or track the code execution path.
  • 20. Key Features ● Real-time debugging ● Step-by-step execution ● Variable inspection
  • 21. How does it work? ● Setting checkpoints in the code ● Run Apex and Get Debug Logs ● Replay of code execution from checkpoints ● Real-time inspection of variables Step-by-step execution and analysis
  • 22. Setting Check Points in the code ● In Visual Studio Code, open the apex class or trigger you want to debug file and focus the cursor on the line where you want to set up the check point. ● Click the View menu then choose Command Palette.... Alternatively, we can use the keyboard shortcut Ctrl+Shift+P (Windows or Linux) or Cmd+Shift+P (macOS) to open the Command Palette. ● Enter sfdx checkpoint in the search box, then choose SFDX: Toggle Checkpoint.
  • 23. Setting Check Points in the code ● We can see an indicator next to the line number showing that the checkpoint was set. ● Open the Command Palette and enter sfdx checkpoint in the search box, then choose SFDX: Update Checkpoints in Org.
  • 24. Run Apex and Get Debug Logs ● With our breakpoints and checkpoints set, it’s time to rerun our Apex test to generate a replay- enabled debug log. ● Run the Apex Code ● In Visual Studio Code,use the keyboard shortcut Ctrl+Shift+P (Windows or Linux) or Cmd+Shift+P (macOS) to open the Command Palette. ● se SFDX: Turn On Apex Debug Log for Replay Debugger. This creates a trace flag to generate replay-enabled debug logs for 30 minutes. You can change the duration in Setup on the Debug Logs page.
  • 25. Run Apex and Get Debug Logs ● After code execution, Open the Command Palette and enter sfdx get in the search box, then choose SFDX: Get Apex Debug Logs ● Choose the debug log associated with the recent Apex Run ● Click Continue button on Debug Toolbar on the Debug Toolbar to continue to the first breakpoint ● Right-click any line in the debug log, then choose SFDX: Launch Apex Replay Debugger with Current File
  • 26. Run Apex and Get Debug Logs
  • 27. ● Benefits ● Faster issue resolution ● Improved code quality ● Time-saving
  • 28. ● Considerations ● Only one debug log at a time ● You can’t replay a debug log generated by scheduled Apex. ● We can’t expand a collection
  • 29. ● Best Practices for Effective Debugging ● Set meaningful checkpoints ● Use logging statements ● Practice regularly
  • 30. ● Live Demo in Visual Studio Code ● Walkthrough of setting checkpoints ● Initiating debugging sessions ● Stepping through code execution ● Inspecting variables