6

Is it possible to have a report that shows "system overview"-like data (storage used, licenses, etc.) sent via email automatically (without writing code) in Salesforce?

Otherwise, what's the best way of doing this by code?

Thanks

1 Answer 1

2

I'm not sure about a "without writing code" solution.

However, here is one using Apex that will send the System Overview page as a PDF attachment.

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
email.setHtmlBody('System Overview Resport attached');
email.setToAddresses(new string[]{'[email protected]'});
email.setSubject('System Overview Report');

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('systemOverview.pdf');
string partialURL = '/setup/systemOverview.apexp?setupid=SystemOverview';
Pagereference systemOverviewPr = new PageReference(partialURL);
efa.setBody(systemOverviewPr.getContentAsPdf());
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.Singleemailmessage[] { email});

Unfortunately the getContentAsPdf() call can't be made from Scheduled Apex. This does spoil the automation side of things. Maybe make a web service that the scheduled apex can callout to. The web service would send the email, and be out of the scheduled apex transaction context.

1
  • Yes, that's what we end with, an apex web service, invoked externally, that scraps the HTML page of System Overview and sends it as an answer to the caller. It's a pity that Salesforce doesn't provide an API for this.
    – friol
    Jun 13, 2014 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .