+ 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:

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

    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

Yes from my understanding this is possible.