Salesforceでzip ファイルダウンロードするサンプルコード
イシュー
- Salesforce で zipファイルをダウンロードするためのサンプルコード
ポイント
- Zipファイルの作成は Zippex ライブラリを使用する
- Salesforceにバイナリ(Blob)をレスポンスする方法がないので、一旦 Documentオブジェクトに格納する
- 非同期でダウンロードを行うために location.href を利用(お手軽)
参考
- GitHub - pdalcol/Zippex: Native Apex Zip library for Salesforce.com
- SFDC:VisualforceでつくったCSVファイルをダウンロードする処理の話 - tyoshikawa1106のブログ
- Salesforce apex クラスで 添付ファイルを保存する。 - 開発メモ
- Excel を作成する場合の参考
- サーバサイドでExcelブックを生成するいくつかの方法 - Qiita
- Excel を作成する場合の参考
- Handling Office Files and Zip Files in Apex – Part 2 | Andy in the Cloud
- Zip Unzipデモ
- Google Code Archive - Long-term storage for Google Code Project Hosting.
- Apex button to Download apex:pageBlockTable as Excel or PDf - Salesforce Developer Community
- apex - Decoding Blob method for the contentversion object through Rest Class - Salesforce Stack Exchange
- Response.body をセットしておけば、バイナリ返せるか(?)
Apex クラス
課題
- ファイルサイズが大きいとエラー(Apex CPU time limit exceeded)
- クライアント側で、Zipの生成を待つ仕組みが必要