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

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[]{'root@eruditorum.org'});
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.

| improve this answer | |
  • 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. – Gabriele D'Antona Jun 13 '14 at 18:03

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.