<apex:CommandButton value="日報出力"
style="width:80px;height:20px; margin-right:auto;margin-right:auto;text-align: center;"
action="{!doInsert}" onComplete="doPrintDailyReport();" />
<apex:actionFunction id="doPrintDailyReport" name="doPrintDailyReport" action="{!doPrintDailyReport}" reRender="mainForm"/>
//日報出力ボタン押下
public void doInsert(){
dailyReport.id = this.id;
try {
system.debug('===this.dailyReport.Memo__c======'+this.dailyReport.Memo__c);
update this.dailyReport;
} catch (DmlException e) {
for (Integer i = 0; i < e.getNumDml(); i++) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getDmlMessage(i)));
}
}
}
//日報出力
public PageReference doPrintDailyReport(){
id attId = reportUpload();
return new PageReference('/'+attId);
}
/*
*日報オブジェクトの添付ファイルを追加
*/
private id reportUpload() {
Pagereference rdPage= new Pagereference('/apex/DailyReport?id='+this.id);
DateTime d = Date.Today();
Attachment att = new Attachment();
att.Name = d.format('yyyyMMdd', 'Asia/Tokyo')+'_'+this.storeCode+'.pdf';
att.Body = rdPage.getContent();
att.Parentid = this.id;
system.debug('att.att.Name '+att.Name );
system.debug('att.Parentid '+att.Parentid );
system.debug('att.Body '+att.Body );
try {
insert att;
system.debug('アップロード完了');
} catch (Exception e) {
system.debug('アップロードエラー');
}
return att.id;
}