Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

When can I use (SeeAllData=true)?

Asked by Aashish Chaursiya Apr 18, 2023 1.3K views 1 answer
Share

About this question

At this point I think we're painfully aware that using SeeAllData=true is one of the 7 Deadly Sins of Salesforce (assuming there's just 7). I know, for example, why we shouldn't use it:

  • Can slow tests down massively if you're accessing a lot of data

  • Querying for a specific record today might be gone tomorrow

  • Could cause tests to pass in sandboxes but fail in production

  • Etc...

I feel at this point I'm regurgitating the same old response to SeeAllData=true:

Using SeeAllData is almost always unnecessary except in the rarest of circumstances.

I realised though I don't actually know when it's useful to use it. So when might it be appropriate to use it? I've never come across a situation yet personally and things like Profiles persist in test classes.

The only reason I think where I could be useful is that we have an object called Source__c which stores a bunch of records there. The name might be Website, Mobile App, CompanyWe'reAPartnerWith1. It's basically interacted with minimally (this was made before the introduction of Custom Metadata Types), but even then I'd just do something like:

Source__c src = new Source__c( Name = 'Website' ); INSERT src;

I read that querying data is more efficient than performing DML in this way (hence @testSetup), so maybe I'm doing that "wrong"?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.