Use the Analytics API via Apex for faster performance and easier maintenance. All the capabilities of the Analytics REST API are also available in the Apex API.
The Analytics REST API, introduced in Winter ’14, gives developers access to many reporting and charting features that were previously available only through the web interface. If your customization strategy rests on Apex coding rather than the REST API, you can now use Apex to make all the same calls you can make with the REST API.
For example, here’s a way you could use Apex to automate a reporting workflow. This Apex code takes a report ID and message as input, runs the specified report, and posts a Chatter message to every user or entity listed as a grouping.
Reports.ReportResults res = Reports.ReportManager.runReport(reportId);
FeedItem[] posts = new FeedItem[res.getgroupingsDown().getgroupings().size()];
for(Integer i=0;i<posts.size();i++) {
FeedItem post = new FeedItem();
post.ParentId = UserInfo.getUserId();
post.Body = message + res.getreportmetadata().getname() + '(' + res.getgroupingsDown().getgroupings()[i].getlabel() + ':' + res.getfactmap().get(''+i+'!T').getaggregates()[0].getlabel()+')';
posts[i] = post;
}
insert posts;
In either case, calls to the Analytics Apex API and to the Analytics REST API count toward the same limits pool.
The Analytics REST API, introduced in Winter ’14, gives developers access to many reporting and charting features that were previously available only through the web interface. If your customization strategy rests on Apex coding rather than the REST API, you can now use Apex to make all the same calls you can make with the REST API.
For example, here’s a way you could use Apex to automate a reporting workflow. This Apex code takes a report ID and message as input, runs the specified report, and posts a Chatter message to every user or entity listed as a grouping.
Reports.ReportResults res = Reports.ReportManager.runReport(reportId);
FeedItem[] posts = new FeedItem[res.getgroupingsDown().getgroupings().size()];
for(Integer i=0;i<posts.size();i++) {
FeedItem post = new FeedItem();
post.ParentId = UserInfo.getUserId();
post.Body = message + res.getreportmetadata().getname() + '(' + res.getgroupingsDown().getgroupings()[i].getlabel() + ':' + res.getfactmap().get(''+i+'!T').getaggregates()[0].getlabel()+')';
posts[i] = post;
}
insert posts;
In either case, calls to the Analytics Apex API and to the Analytics REST API count toward the same limits pool.
Comments
Post a Comment