You need to sign in to do that
Don't have an account?
Generating Reports in xl format without data.
Hi,
I am generating reports in xl format, attaching it, sending mail using apex class and scheduling it.
If I run this code using developer console I am getting all the report data. But, If I run the code using schedule job my generated xl file is showing with some script tag.
Pagereference ref = new Pagereference('https://--.salesforce.com/{ReportId}?export=1&enc=UTF-8&xf=csv');
Blob b = ref.getContent();
System.debug('----content--->'+b);
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
String dt = String.valueof(system.today());
efa.setFileName('24hrsDeals - DGL Units Received '+dt+'.csv');
efa.setBody(b);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new string[]{'asc.sfdc.tester@gmail.com'};
email.setSubject( 'Test' );
email.setToAddresses(toAddresses);
email.setPlainTextBody('Test');
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
Below is the generated xl file when scheduling.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<script>
var escapedHash = '';
var url = 'https://test.salesforce.com/?ec=302&startURL=%2F00OA00000044eKD%3Fxf%3Dcsv%26export%3D1%26inline%3D1%26enc%3DUTF-8';
if (window.location.hash) {
escapedHash = '%23' + window.location.hash.slice(1);
}
if (window.location.replace){
window.location.replace(url + escapedHash);
} else {;
window.location.href = url + escapedHash;
}
</script>
</head>