+ Start a Discussion

Bug in Apex Tes Methods and v24



Not sure if this is expected behavior or not but:


Test Method that looks at the share records for an object, in v24, fails unless seeAllData is set to true. Even if you create all records in the test methods and use test.startTest() and test.stopTest() appropriatly.


Here is sample code to run to show no records are returned for the share (Not even rowcause = owner). In v23 this works). This means that you must set seeAllData = true in your test methods to test the sares.....One would think you would be able to see shares created as a result of your test records...


private class TestBug{

    private static testmethod void testAccount(){
        Account a = New Account(
            Name = 'Testing',
            shippingcity = 'test',
            shippingstate = 'OH',
            shippingstreet = 'test street',
            shippingpostalcode = '41111',
             ownerID = userinfo.getUserID()
         insert a;
         Accountshare[] ashare = [Select ID, RowCause, AccountID, UserOrGroupID From Accountshare where Accountid =:a.id];





You should probably put something soft and padded on your desk before reading this:




Thanks for the info:


I however read the:


a SOQL query will now only retrieve objects that have been inserted during the course of the unit test


It should have access to ANY records created during the course of a unit test. I understand the pricebook becuase you cannot create those records. But a share is created during the unit testing as a result of the record you inserted during the unit test.


poor implementation if you ask me.


This also means, if I can infer correctly, that any records created from a trigger on an record that was inserted during a unit test will also NOT be avaliable for comparison.....


This needs to be fixed... I am all for creating your own records during testing, but this limitation essentially makes this new feature USELESS


Yeah, the behavior is what I'd call "wonky." It seems like you never know what to expect until you try it.


Thanks for the bug report and concise test. The AccountShare sobject should be visible. I'm looking into this now.


Thank you...


I really needs this for Custom Object shares as well so please do not limit to Standard Object Share.



I am curious if the reason is because the share does not have a CreatedDate field and just has a lastModified date (at least visible to me);


The reason is just a byproduct of the way Share objects are auto-inserted. It's really just weird special case in our architecture. I'll fix this (for standard and custom object shares). I hope to get this out in a patch soon.


That makes me worried about object like the OpportunityPartner object, although I have a feeling that's just like a view on the Partner object.