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
RoyalRoyal 

@IsTest(SeeAllData=true) ?

when i use SeeAllData=true on test class, can able to query the records from org, and able to insert, update but not able to delete, why ?
see the below test class after delete statement assert statement is failing, can you please look into this .....  
@IsTest(SeeAllData=true)
private class TestClassOnVenkat{
  static testmethod void InsertRec(){
   venkat__c a=[select id,name from venkat__c where name='name value'];
   Venkat__c b=a.clone();
   b.name='cloneed name value';
   Test.startTest();
   insert b;
   venkat__c c=[select id,name from venkat__c where name='cloneed ZZZZZ'];
   System.assert(c != Null);   
   c.name='Update name value';
   update c;
   System.assert(c.name=='cloneed name value');   
   delete c;
   System.assert(c == null);   
   Test.stopTest();  
  }
}

Thanks
Best Answer chosen by Royal
edoardo_spanoedoardo_spano
Hi guy,
you're deleting the record. The variable is still set.
Try to replace the last assert with:
List<venkat__c> vlist = [SELECT Id, Name FROM venkat__c WHERE Id = :c.Id];
system.assert(vlist.size() == 0);

All Answers

Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi,

Since test methods don’t commit data created in the test, you don’t have to delete test data upon completion.
For more info ,please refer https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_testing.htm|StartTopic=Content%2Fapex_testing.htm|SkinName=webhelp

Let us know if it helps you.
edoardo_spanoedoardo_spano
Hi guy,
you're deleting the record. The variable is still set.
Try to replace the last assert with:
List<venkat__c> vlist = [SELECT Id, Name FROM venkat__c WHERE Id = :c.Id];
system.assert(vlist.size() == 0);
This was selected as the best answer
RoyalRoyal
Hi Edoaero,
your right, now passing the test class,
i have two more doublts can you pls clarify me
1. but what is reason for that, i mean only list records can we able to delete or we can not able to delete set and individual records ?, is it that means ? 
2. and one more is if use SeeAllData=true that class or method can have access org data, so i think we cannot perform the DML operations on org data but we can able here, is there any imfact on org Data ? if not why ?

thanks you so much for your reply.
edoardo_spanoedoardo_spano
Hi,
1. You can either delete list of record or individual record. Your code is correct. It wasn't correct only the last System.assert. When you delete a record (or list of records), the variable that contains that record (or list) is still populated. So, if you check the value of a variable after a delete operation, it is still "!= null".
2. No, there are no impacts on org data, because the test classes don't commit the DML operations, also with the "SeeAllData=true" annotation.

Let me check if it is all clear now.

Bye
madhan bondalapatimadhan bondalapati
Hi edoardo

what the main purpose of having seealldata=true in the test class.Could you please explain withone example.?

Thanks