I have a custom object Owner__c which has only 4 rows of record.

Here i have written test suite class

With given code below

1) 1st STEP i have fetched the values with id and checked with assert method

2) 2nd STEP i deleted the record through the list.

3) 3rd STEP i fetch records from the owner object and checked with assert statement

4) Then i want to insert record... but i couldn't since the records has not been deleted

private class OwnerTestController {

  static testMethod void executeOwnerSuite(){

    List<Owner__c> ownerList = null;

    Test.startTest();  // Start Executing the test

    List<Owner__c> owners = [SELECT Id, Owner_Id__c, Owner_Code__c, Name  FROM Owner__c ];

    // 1st STEP --> Here I check the list which should not be null  
    System.assert(true, owners!=null); 

    delete owners;  // 2nd STEP --> deleting the record

    owners = [SELECT Id, Owner_Id__c, Owner_Code__c, Name  FROM Owner__c ];

    // 3rd STEP --> Here I check the list is null after deleting the record     
    System.assert(true, owners==null);  

    Test.stopTest();  // Stops the test execution


Do i make any mistake in the above code? Since the record has not been deleted. Is it right way executing a test suite?

In eclipse i'm not able to find any test result, whether it is passed or failed.

In Apex test result i find it is passed, but none of the records has not been deleted.

Kindly help me and let me know in case of any further information.

Below i have given the screen shot

enter image description here

1 Answer 1


The problem is that your test class doesn't have any data to operate on; by default test methods cannot see your org's data unless you specify seeAllData=true. You need to either setup test data (preferred method) or use seeAllData (use cautiously).

For more example, please read Understanding Test Data and the sections following it.

  • 1
    In addition to Mike's answer, the typical way tests are written is that they: 1. insert some test data, in this case Owner__c records. 2. Perform some operation on these test records within Test.startTest(); and Test.stopTest();, in this case the delete operation 3. Use assert statements to verify that the outcome is exactly what was expected, in this case it's that a record was deleted.
    – Mark Pond
    Oct 15, 2013 at 17:17
  • @ Mike: Thanks Mike for giving an info, i added @isTest(SeeAllData=true) at class level still having the same issue. Here in my case, already i have the data so i have given the insert statement at 4th step. Do i miss anything?
    – Arun
    Oct 16, 2013 at 18:11
  • At step 1 (after the initial SELECT), if you do a System.debug(owners.size()); is it greater than 0?
    – Mike Chale
    Oct 16, 2013 at 18:28
  • @Arun you are going to want to insert as step 1. Step 1, insert. Step 2, query. Step 3, delete. Step 4, assert. Step 5, continue on with your desired insertion at this point. Oct 16, 2013 at 19:04
  • Thanks for all your comments and i done the same. Sorry for the late reply
    – Arun
    Nov 7, 2013 at 16:47

You must log in to answer this question.

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