【问题标题】:Can any one tell me how to schedule the exporting of salesforce report in csv format谁能告诉我如何安排以 csv 格式导出销售人员报告
【发布时间】:2013-03-21 07:58:33
【问题描述】:

我有一份销售人员报告,我希望每天以 csv 格式安排此报告,以便用户收到带有此附件的邮件。

【问题讨论】:

标签: salesforce


【解决方案1】:

您可以使用以下代码安排报告

global class ExporterCSV implements System.Schedulable {
global void execute(SchedulableContext sc) {
List<Merchandise__c> acclist = [Select id , name , CreatedDate , lastModifiedDate from Merchandise__c limit 10];
string header = 'Record Id , Name , Created Date , Modified Date \n';
string finalstr = header ;
for(Merchandise__c a: acclist)
{
   string recordString = a.id + ',' + a.Name + ',' + a.CreatedDate + ',' + a.LastModifiedDate + '\n';
   finalstr = finalstr + recordString;
}
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(finalstr);
string csvname= 'Invoice.csv';
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'test@salesforce.com'};
String subject = 'Merchandise Report CSV';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody('The Merchandise report is attached here.');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
  }
}

【讨论】:

    【解决方案2】:

    这是我由 Kevindotcar 找到的解决方案:

    http://kevindotcar.wix.com/home/apps/blog/how-to-schedule-a-report-to-send

    涉及自定义对象、visualforce 页面、visualforce 电子邮件模板以及可调度类和工作流。不过看起来相当整洁,没有太多代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多