Skip to content

Instantly share code, notes, and snippets.

View c4tch's full-sized avatar

Matt Evans c4tch

View GitHub Profile
@c4tch
c4tch / sfdx-throttle-platformevents.apex
Created February 5, 2020 18:06
Throttle Apex Platform Events to avoid overloading trigger DML
/**
* Entrypoint from the Trigger, dispatch the events here
* Bobby White
* The use case is universal... you're never going to be able to consume 2000 PE in a single Apex transaction if the PE are independent.
* You have to "clip" the executions into manageable chunks.
* Best case N = 200, in practice if the DML's will touch objects that are poorly governed, it could hit limits at a lower number like 25 or 50.
* Q: What is "Independent"?
* A: Let's say that you had a flood of PE's that had the applied to the same ExternalId, you might be able to consume these with a single DML (e.g. 10 meter readings for the same Meter, or a series of notifications for the same Client) -- if your use case doesn't demand that you preserve every state change, you could collapse them into one. My default assumption is that you need to design your PE trigger with the premise that the PE's stand alone and have no correlation to other PE's in the same invocation.
* I get you, so in the PE loop you have here you might collapse sim
@c4tch
c4tch / sfdx-install-dependencies.sh
Created January 23, 2020 19:29
SFDX Bash Script for Installing Packages with Dependencies
#!/bin/bash
# The execution of this script stops if a command or pipeline has an error.
# For example, failure to install a dependent package will cause the script
# to stop execution.
set -e