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
Sebastian OjedaSebastian Ojeda 

Can a soql query for a report be a static class variable?

I'm trying to pinpoint an error with a test class using a static variable for a query on Report. Given below test class:

@IsTest
private with sharing class Example_Test_Class {
    private static String testReportName = 'My Test Report';
    private static Report testReport = [SELECT Id FROM Report WHERE Name=:testReportName LIMIT 1];

    @IsTest(SeeAllData=true)
    private static myTestMethod() {
        // Access testReport.Id here
    }
}
Is this valid? I'm not getting any compiler errors but this feels like a possible code smell.
Prafull G.Prafull G.
Hi Sebastian - Looks like you need to either include SeeAllData=true at class level or move your query inside the method. Let me know if this helps.
Raghu NaniRaghu Nani
Hi,

Yes from my understanding this is possible.