よくあるので、忘れないようにメモっとく。
というかソースをそのまま貼る。
仕様概要
・チェックした取引先責任者の役職を"hogehoge"に一括で更新します。
・200件以上の場合は、200件ずつ処理します。
・処理経過をウィンドウを開き表示します。
・OnClickJavaScriptです。
{!REQUIRESCRIPT("/soap/ajax/17.0/connection.js")}
var records ={!GETRECORDIDS($ObjectType.Contact)};
if (records[0] == null) {
alert("レコードを選択してください。");
} else {
var Wait = WaitWindow(records);
var Cnt = 0;
var sfdcObjects = [];
for (var n in records) {
var c = new sforce.SObject("Contact");
c.id = records[n];
c.Title = 'hogehoge';
sfdcObjects.push(c);
Cnt++;
// 200件ずつ処理
if ( (Cnt != 0 && Cnt % 200 == 0) || Cnt == records.length) {
try {
var saveResult = sforce.connection.update(sfdcObjects);
} catch(e) {
alert("処理に失敗しました。再試行してください。");
}
Wait.document.getElementById("ExecCnt").innerHTML = Cnt;
sfdcObjects = [];
}
}
if (Wait != null && !Wait.closed) {
Wait.close();
}
window.location.reload();
}
function WaitWindow(records_1){
var WinObj = "";
WinObj += "";
WinObj += "<title>更新中</title>";
WinObj += "<center>";
WinObj += "
<table border="0" height="100%" style="font-family: Verdana,Helvetica; font-size: 11pt; font-weight: bold;">"; WinObj += "<tbody>
<tr><td align="center">";
WinObj += "" + records_1.length + "件中<span id="ExecCnt">0</span>件処理完了
しばらくお待ちください< /span>"; WinObj += "
</td></tr>
"; WinObj += "
<tr><td align="center">";
WinObj += "
</td></tr>
"; WinObj += "
<tr><td align="center">";
WinObj += " ";
WinObj += "
</td></tr>
"; WinObj += "</tbody></table>
";
WinObj += "
</center>";
var win = window.open("","waitWindow","width=250,height=150,resizable=no,toolbar=no,status=no,scrollbars=no,menubar=no,directories=no,location=no,dependant=no");
win.document.write(WinObj);
return win;
}

0 件のコメント:
コメントを投稿