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
Newbie  2014Newbie 2014 

Any default record locks (READ-ONLY permission) possible from test classes?

Hello: I am trying to delete/insert from a test class and positive that the code is error free; my code can retrieve values (i.e. read) from the record I specify alright, but if I want to delete it (i.e. perform write operation), nothing happens! The test class passes, but no deletion happens. Feels like as if the test class has READ-ONLY permission only. Allow me to explain by looking as my code below:

@isTestDel(SeeAllData = True )
public class deleteAcc
{
static testmethod void unittest() {

delete [select id from account where id = '001m0000004Ey05AAC'];
}
}

Just to test something simple, I have hardcoded the id. From developer console if I execute the select statement above, it returns valid result. But when I try to delete the record, does not work. I have googled a whole lot and tried variations of the delete statement using Lists etc., no luck. Then tried to insert a record on the fly and delete the same, insertion didn’t happen to begin with but class ran fine. Tried to delete all records w/o specifying ids, didn't help. Then tried with different kind of objects, acocunts and opportunitylineitem; no luck.

All these leads me to believe my test class does not have write permission on the objects and I am clue less how to un-do that. Any help will be a life saver. Thanks very much
Best Answer chosen by Newbie 2014
ShashForceShashForce
Hi,

Test classes cannot do DML. They will not be able to edit/delete actual records. They will only act/enact as if they are deleted. It is like a "What If" situation. Only actual classes/methods which are nit test classes/methids can perform actual creates, edits and deletes. Hope this answers your question. Any specific reason you want to modify data through test classes?

Thanks,
Shashank 

All Answers

ShashForceShashForce
Hi,

Test classes cannot do DML. They will not be able to edit/delete actual records. They will only act/enact as if they are deleted. It is like a "What If" situation. Only actual classes/methods which are nit test classes/methids can perform actual creates, edits and deletes. Hope this answers your question. Any specific reason you want to modify data through test classes?

Thanks,
Shashank 
This was selected as the best answer
Newbie  2014Newbie 2014
Thanks a million for your reply, ends my two whole days of trials : (.

Having said that, here are my reasons: I wrote a 'after delete' trigger on opplineitem table and it works fine if i manually delete records for those objects. Needed to deploy it, but it had code coverage as 0%. Googling said needed to write test classes to improve that. I didn't realize test classes won't execute but if they pass my trigger will keep earning scores! After getting your email, I checked the trigger coverage and it is 100% already. So all my passes tests been serving the purpose and I never realized. Well, there is a first time of everything I guess. Thanks a whole lot again, greatly appreciate the fact!