+ Start a Discussion
SFDC HedgehogSFDC Hedgehog 

I'm going to eventually run into SFDC Governor limits - any ideas for slowing the train?

Hi everyone,
I need to send some reports to a user as email attachments.
Currently, I use reportResults.reportMetadata to run the report and I insert the resuls via a component that's inserted on a VF messaging template.

The template looks like this;
<messaging:emailTemplate subject="Excel Data Export of Edgecast Reports" recipientType="User" >
<messaging:plainTextEmailBody >

Hi,

please find attached the report(s) you have requested...

Kind regards,
{!$Organization.Name}
</messaging:plainTextEmailBody>

 <messaging:attachment filename="VESOpportunity.HTML">
 <c:ReportOpportunityExportController xstrRptname="00O50000004TUS9"/>
 </messaging:attachment>

</messaging:emailTemplate>
The Component looks like this;
<apex:component controller="SyncReportController" access="global">
<apex:attribute name="xstrRptname" description="report ID" type="String" assignTo="{!reportId}"/>
<!-- apex:outputText value="{!ReportResults}" escape="false"/ !-->
  <style>
      table.reportResults {
          width: 100%;
      }
  </style>
  <apex:outputPanel id="reportResults" layout="block">
      <apex:outputPanel >
         <table class="reportResults">
           <thead>
               <apex:repeat value="{!reportResults.reportMetadata.detailColumns}" var="colName">
                   <th><apex:outputText value="{!reportResults.reportExtendedMetadata.detailColumnInfo[colName].label}"/></th>
               </apex:repeat>
           </thead>

           <tbody>
               <apex:repeat value="{!reportResults.factMap['T!T'].rows}" var="row">
                   <tr>
                       <apex:repeat value="{!row.dataCells}" var="cell">
                           <td><apex:outputText value="{!cell.label}"/></td>
                       </apex:repeat>
                   </tr>
               </apex:repeat>
           </tbody>
         </table>
      </apex:outputPanel>
  </apex:outputPanel>
</apex:component>
The component controller looks like this;
public with sharing class SyncReportController {

    public Id reportId { get; set; }
    public Id instanceId { get; set; }
    public Boolean reportIsRunning { get; set; }
    private transient Reports.ReportResults reportResults;

    public SyncReportController() {
        }

    public void setReportId(String theReport) {
        reportId = theReport;
        }

    public PageReference runReport() {
        reportResults = Reports.ReportManager.runReport(reportId, true);

        return null;
    }

    public Reports.ReportResults getReportResults() {
        reportResults = Reports.ReportManager.runReport(reportId, true);
        return reportResults;
    }
}

The trouble is pretty obvious;  
if the report returns more than 1000 rows the messaging will fail because of the apex:repeat call, and this report can return maybe five thousand rows.

My temporary solution is to filter the report into three different reports, based on a report-logic specific filter criteria, but that too will eventually fail.

Ideally, I would like something equivalent to "readonly=true" on the apex:component tag - It would make sense for SFDC to support this, because it is in effect a "page". but that's not going to happen.

I tried remoteObject but that is limited to 100 objects per call.
I used to be able to insert a report directly as an attachment but that has gone away since SFDC does not allow 
PageReference(requestURL).getContent()
On email services anymore...

Does anyone have any ideas? 

Many thanks,


 
Andy BoettcherAndy Boettcher
Ok, left field questions time.

- Do you HAVE to email these reports to the person?  If they're a SF user, can't they just run the report?
- Can you expose this data any other way (thinking external reporting tool with you already invoking the Metadata/Reporting API?
- IMHO, 5000 rows on a single report is a pretty useless report.  Any chance of breaking up the report into multiple ones?
SFDC HedgehogSFDC Hedgehog
Hi Andy,

Good questions !

-   No, they are *NOT* an SFDC user in our org, and that's specifically why they are a "BCC" on a email alert - we don't want them poking around in our org, although I could prolly mess with the administration of a custom profile to make sure that they have no access, but that is a heavy lift.

-  I was thinking of Conga (we use Conga a lot), But that would require some manual intervention, and setting up a specific machine for the purpose of sending the report... I'd rather keep everything in SFDC, but I'm rapidly getting painted into a corner.

-  The "Report" -- which is actually given as a CSV is being used by the end user as a data load into their SFDC instance - so it's not a "report", per se.   And they specifically will not allow Salesforce to Salesforce.

Thanks for the response - I have a temporary work-around using dynamic VF components, but it still is a nail in my head.

 
Andy BoettcherAndy Boettcher
OOOOO - your last one about the CSV...why not just generate that in a Scheduled Apex job and shoot it via email?
SFDC HedgehogSFDC Hedgehog
Hi Andy,

Thanks for the reply.

I guess I could, but I'm trying to keep the destination user out of our instance.
Right now they are set up as a "CC" on the email template - which makes administration of this "non-user" very easy.
Otherwise, I'm going to have to worry about them poking around.... 

Plus, like i said, they need to use the data for an import into their SFDC instance -- and emailed reports don't do that very well.... unless there's something I'm missing.  Right now, They can handle an HTML file or a CSV file well enough, so I have to manage that user-expectation.

I wish "scheduled reports" had a format option that included "CSV/UTF-8/HTML/etc.."  but unfortunately that's not anoption.

I'm going to look at this solution;
https://help.salesforce.com/apex/HTViewSolution?id=000003176&language=en_US

...But since scheduled APEX doesn't have VF page context, I'm not holding out much hope -- but  any suggestions are of course welcome :-)

Hedge
 
SFDC HedgehogSFDC Hedgehog
Hi again Andy -
It just occurred to me - are you talking about generating the entire report via APEX - from the SOQL to the CSV formatting?   That of course is an option, but, that seems like an awful heavy lift... Plus, it takes the formatting of the data out of the habds of the business stakeholders and into the hands of the developers -- which salespeople *always* hate :-(   They want to keep ownership of these reports -- as it is their sales data.
 
Andy BoettcherAndy Boettcher
Yup!  Yeah, it's a huge lift, but it's an option.  =)