Created
April 27, 2020 13:41
-
-
Save msrivastav13/a4bc029440f34ed70b88d00d248f9fc5 to your computer and use it in GitHub Desktop.
Rollback platform events example with Savepoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<PlatformEvents__e > events = new List<PlatformEvents__e >(); | |
// Created a PlatformEvents with a Message__c field of 30 characters only, so second event fails | |
events.add(new PlatformEvents__e(Message__c='Test')); | |
events.add(new PlatformEvents__e(Message__c='ldjgkfjgkfjkjhkgjhkgjhkghkghkgkhkghkghkghkghkghghkghkghkghkghghkghkghkghkghghkghkghkghkghghkghkghkghkghghkghkghkghkgh')); | |
Savepoint sp = Database.setSavepoint(); | |
// Call method to publish events | |
List<Database.SaveResult> results = EventBus.publish(events); | |
for(Database.SaveResult result: results) { | |
if(!result.isSuccess()) { | |
Database.rollback(sp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current Limitation Discovered -- No support for
allorNone
in the apexEventBus.publish