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
Starz26Starz26 

Bug in Apex Tes Methods and v24

Greetings,

 

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...

 

@isTest
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()
            );
         test.startTest();  
         insert a;
         test.stopTest();
         Accountshare[] ashare = [Select ID, RowCause, AccountID, UserOrGroupID From Accountshare where Accountid =:a.id];
         system.debug(ashare);
           
    
    }



}

 

 

craigmhcraigmh

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

 

http://stackoverflow.com/questions/9164986/how-do-i-avoid-standard-price-not-defined-when-unit-testing-an-opportunitylineit

Starz26Starz26

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

craigmhcraigmh

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

rungerrunger

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

Starz26Starz26

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);

rungerrunger

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.

craigmhcraigmh

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.