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

Sharing Records are not queried in Test Class.

I want to create Opportunity Share records for two custom fields "Manager" and "Senior Manager"  lookup to User on Opportunity object. 

My Batch job is working as expected and creating those record perfectly. 

But, the issue is in Test Class:
  • I have created one createOpportunity() method, and create two Opportunities. 
  • Both the opportunities have Manager / Senior Manager field populated with User. 
  • Now, when I run this method, It will cover my Batch job and create sharing records ( that I can debug in batch job).
  • If I am trying to query those sharing record in Test Class using below query, it is giving 0 records. 
  • SELECT Id, manager__c, senior_manager__c, rowcause from Opportunity. 
Any ideas please. 
Can you share your test class code?

Thanks for your response, but unfortunetly I can't. 

If you have any particular blog / article which is calling covering Batch Class code for Sharing records. Please share. 

Use @isTest(seeAllData=true) on the test class and run your test class on the org data. This way it will fetch the sharing record.