3

I am trying to find some answers from few days, but not able to clear them. Can anybody please help me out with it.

A apex class suddenly stopped working.

Apex code -

`

List<Reports.ReportFilter> filList = new List<Reports.ReportFilter>();
fil = new Reports.ReportFilter('Financial_Journal_Line__c.Transaction_Date__c','lessOrEqual',eDate.year()+'-'+eDate.month()+'-'+eDate.day());
                    fil2 = new Reports.ReportFIlter('Financial_Journal_Line__c.Posted__c','equals','true');
                    fil3 = new Reports.ReportFIlter('Financial_Journal_Line__c.Financial_Summary__c.Name','equals','');
filList.add(fil);
filList.add(fil2);
filList.add(fil3);
Reports.ReportMetadata meta = new Reports.ReportMetadata();
meta.setReportFilters(filList);
meta.setReportBooleanFilter(booleanFilter);
meta.setHasRecordCount(true);
meta.setAggregates(new List<String>{'s!Financial_Journal_Line__c.Amount__c','s!Financial_Journal_Line__c.Debit__c','s!Financial_Journal_Line__c.Credit__c','RowCount'});
Reports.GroupingInfo gi = new Reports.GroupingInfo();
gi.setName('Financial_Account__c.Id');
gi.setsortOrder(Reports.ColumnSortOrder.ASCENDING);
gi.setDateGranularity(Reports.DateGranularity.NONE);
List<Reports.GroupingInfo> gil = new List<Reports.groupinginfo>();
gil.add(gi);    
meta.setGroupingsDown(gil);
meta.setHasDetailRows(true);
meta.setDetailColumns(new List<String>{'Financial_Journal_Line__c.Account_Number__c','Financial_Journal_Line__c.Transaction_Date__c','Financial_Journal_Line__c.Name','Financial_Journal_Line__c.Description__c','Financial_Journal_Line__c.Amount__c','Financial_Journal_Line__c.Debit__c','Financial_Journal_Line__c.Credit__c','Financial_Journal_Line__c.Financial_Summary__c.Id','Financial_Journal_Line__c.Manual_Journal__c','Financial_Journal_Line__c.Chit_Processing__c'});

Reports.ReportManager.runAsyncReport(reportId2, meta, true);

meta.setHasRecordCount(true);
meta.setAggregates(new List<String>{'s!Financial_Summary__c.Actual__c','s!Financial_Summary__c.Debit__c','s!Financial_Summary__c.Credit__c','RowCount'});
Reports.GroupingInfo gi = new Reports.GroupingInfo();
gi.setName('CUST_ID');
                        gi.setsortOrder(Reports.ColumnSortOrder.ASCENDING);
gi.setDateGranularity(Reports.DateGranularity.NONE);
List<Reports.GroupingInfo> gil = new List<Reports.groupinginfo>();
gil.add(gi);           
meta.setGroupingsDown(gil);
meta.setDetailColumns(new List<String>{'Financial_Summary__c.Actual__c','Financial_Account__c.Account_Number__c','Financial_Summary__c.Debit__c','Financial_Summary__c.Credit__c'});

Reports.ReportManager.runAsyncReport(reportId, meta);

`

-------I am getting error in console 'null is not a valid scope' in method runAsyncReport at line 38. Earlier this method was not giving any error.------- This error was not coming earlier as my report was generating but now report is not generating may be because of this error.

and when i remove meta from this method call it runs successfully.

So i am blaming Salesforce Winter '16 release because earlier it was working fine.

Reason after some research-

-> if it uses API Version for upgrade i have not changed API Version?( this class is using Report API so, if my class is of lesser API version then also it will call upgraded Report API? Because I saw release notes of Winter '16 it was mentioned that they changed Report API).

-> or it may not use API version for upgrade i.e it may upgrade automatically with salesforce upgrade?

I am not clear how apex classes upgrades with new version of Salesforce.

Can anybody explain me how our code gets updated with new release of salesforce.

Please answer what you guys know.

  • 1
    Can you please edit your post to make it more clear what you mean by "stopped working" and perhaps share the affected code? Please include any code and error messages verbatim. – Adrian Larson Nov 16 '16 at 13:57
  • You have posted 36 lines of code and say that the error is in line 38 which isn't too helpful... But if you are sure nothing else has changed then yes perhaps it is a non-versioned API change in runAsyncReport. Suggest you raise a support case with Salesforce to report it and meanwhile try to figure out what an appropriate value for scope is to work-around the problem. – Keith C Nov 16 '16 at 17:38
  • 'null is not a valid scope at line number 38 in runAsyncReport'. It is the line number of this method on which its giving error . I dont know what exactly is written in this method. Is there's any way i can see this method defination? – jyoti Nov 17 '16 at 5:45
  • 1
    @jyoti You can't see the implementation of the method but the API says scope is a String so if you can figure out the right value you can set that on the Reports.ReportMetadata object. – Keith C Nov 18 '16 at 17:00
4

I am not sure but this problem has introduced after winter17 release and before to this release ReportMetadata class was allowing to set the reportScope as null but now I think its mandatory to set the reportScope by using setScope() of ReportMetadata class.

just set the scope as follow in your code.

 Reports.ReportMetadata meta = new Reports.ReportMetadata();
                meta.setReportFilters(filList);
                meta.setScope('organization');

And change

Reports.ReportManager.runAsyncReport(reportId, meta);

to

Reports.ReportManager.runAsyncReport(reportId, meta,true);
| improve this answer | |
2

On the subject of the API version that a class works against...

The aim of the platform is that you can write code against a specific API version - e.g. 36.0 - and that code will continue to work the same way in future versions of the platform. So you don't need to change the API version that your class works against.

Over time Salesforce adds methods and occasionally changes existing methods to behave differently. If you want to "opt in" to the new methods or behavior change the API version that your class works against (and make sure your unit tests still pass and perhaps do a bit of manual testing too).

Very occasionally a platform change slips through that isn't guarded by the API versioning and your code can be broken by the platform change. But don't assume that this is the problem.

Some more opinion on the subject: What is the best practice re: API Version of your Apex Classes?

| improve this answer | |

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.