7

Winter 14' gives the ability to run and get report data, but I can't find anything about creating reports dynamically in the API documentation - http://www.salesforce.com/us/developer/docs/api_analytics/index.htm

I am writing unit tests for some reporting functionality and I can't rely on one client having the same reports as another, so I need to mock some reports. I found this answer about making report folders programatically, but nothing about reports. Is there a way to create reports via apex?

EDIT - after search a lot more, I found that you can't create a report from SOQL.

However, I did find some guidance from Salesforce about how to test reports in the Reporting API.

1

You can't create a report programmatically from a unit test. You might be able to do it with the Apex Wrapper Salesforce Metadata API from outside of a unit test context, though.

I'm not sure of the design of your program, but maybe you can abstract away the report to a data source interface and mock that in your unit tests. E.g.,

public class MyReportService {
    DataSource source;
    public MyReportService(DataSource ds) {
        this.source = ds;
    }

   // Bunch of other methods that do things with with data source.
}

Then in your unit test:

DataSource myMockDataSource = generateMyMockDataSourceSomehow();
MyReportService service = new MyReportService(myMockDataSource);

Test.startTest();
Integer retVal = service.answerMagicalQuestion();
Test.stopTest();

System.assertEquals(42, retVal, 'magical answer wrong');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.