function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
asadim2asadim2 

deleting data in test methods -100% safe?

Hey all,

 

Sometimes I need to wipe off data from certain tables to simulate a more accurate use case for my test methods. But I'm wondering if it's entirely safe to call delete on a table? I know that the data is only deleted for that particular test case, but does anybody know how exactly this happens? Is it just a "pretend delete?"

 

I'm having some "what-if" concerns, like, what if all of a sudden SF crashes? Will I have to resort to voodoo in order to get my data back? Basically, how safe is it to call delete on a table in a test case?

 

Thanks much!

 

P.S> I know that API v24.0 runs test cases without looking at the existing org data, but there's some dependency between my tests and the org data. So, that's not really what I'm looking for here.

sfcksfck

It's safe. It doesn't really delete anything. It creates a test environment which behaves as if the data has been deleted. 

 

 

Navatar_DbSupNavatar_DbSup

Hi,

 

Whenever you create an Apex Class (in Visualforce terms it may be called a controller or an extension), and when you want to move your Apex Class to production it is necessary that you have a Test Method for your Apex Class. Moreover, the test coverage for your Apex Class should be NOT less than 75%.

 

Starting with Apex code saved using Salesforce API version 24.0 and later, test methods don’t have access by default to

Pre-existing data in the organization, such as standard objects, custom objects, and custom settings data, and can only access Data that they create. However, objects that are used to manage your organization or metadata objects can still be accessed in Your tests such as:

• User

• Profile

• Organization

• RecordType

• ApexClass

• ApexTrigger

• ApexComponent

• ApexPage

You must create test data for each test.

 

Test code saved against Salesforce API version 23.0 or earlier continues to have access to all data in the organization and its data access is unchanged

Here we usually make use of sample data, whenever we make use of delete command in test method then it does not affect the organization data (Isolation of Test Data from Organization Data)

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.