If you have a test set to SeeAllData=true, and you publish a platform event that has a trigger that inserts a record, will that data actually be created in the org?

trigger PlatformEvent on NameSpace__PlatformEvent__e (after insert) {        
    insert new Account(Name='created from a test');

public class Test_PlatformEvent{
    public static void runTest(){
        NameSpace__PlatformEvent__e event = new NameSpace__PlatformEvent__e();
  • 12
    You know what? It did leak data. I'm going to go tell some people now.
    – sfdcfox
    Sep 30, 2017 at 4:14
  • So in this case inserted account will exist after finish of test execution? Sep 30, 2017 at 5:34
  • 3
    @AlexanderBerehovskiy yes. I have a reproducible example in my dev org. Tried it a few times to verify that I'm not crazy.
    – sfdcfox
    Sep 30, 2017 at 5:37
  • @sfdcfox - do you know if this was ever fixed?
    – Eric
    Dec 29, 2017 at 1:45
  • 2
    @Eric It appears that the bug has been resolved. I ran the test just now, and no data was leaked.
    – sfdcfox
    Dec 29, 2017 at 3:09

3 Answers 3


It is possible to set up data that will be global for all test methods.

Use @testSetup annotation for ONE static method inside the test class.

This method will be called before all the test methods in its own scope of limits and create required data.

Your test methods in their turn must query the data they need.

See Using Test Setup Methods for more details.

  • It has nothing to with test environment. There was bug in SF that caused platform event data to leak in actual data which is discussed in comment section. May 8, 2018 at 9:06
  • @PranayJaiswal, you are right - I was mislead by the question in the subject May 8, 2018 at 9:21

Click here to see the details, another discussion with the same topic. Test Class SeeAllData=true Annotation

It never creates or executes any DML on your org data, marking seeAllData=true opens up the access to data but any data you are creating/modifying in test class stays till scope of test class.


At the end of any test, all DML operations are rolled back, so even with seeAllData none of your production data should be changed.

This is because all test classes need to be run in production during deployments, and no one wants tests interfering with live data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .