undelete()
ごみ箱からレコードを復元します。
構文
1UndeleteResult[] = connection.undelete(ID[] ids );使用方法
このコールを使用して、削除済みのレコードの中で復元可能なレコードを復元します。復元可能なレコードには、ごみ箱の中にあるレコードも含まれます。レコードは、merge() または delete() コールの結果として、ごみ箱に入れられる場合があります。queryAll() コールを使用して、結合の結果として削除されたレコードなど、削除されたレコードを識別することができます。
削除する前に、レコードが復元できることを確認する必要があります。復元できないレコードもあります。たとえば、Account レコードは復元できますが、AccountTeamMember レコードは復元できません。オブジェクトが復元できることを確認するには、そのオブジェクトの DescribeSObjectResult の undeletable フラグの値が true に設定されていることを確認します。
delete コールは、子レコードをカスケード削除しますが、undelete コールは、カスケード削除されたレコードを復元します。たとえば、取引先を削除すると、その取引先に関連するすべての取引先責任者を削除します。
結合の結果として削除されたレコードを復元できますが、子オブジェクトに再設定された親を元に戻すことはできません。
このコールは、AllOrNoneHeader、AllowFieldTruncationHeader、および CallOptions ヘッダーをサポートしています。
エラー時のロールバック
AllOrNoneHeader ヘッダーを使用すると、すべてのレコードが正常に処理されない限り、すべての変更をロールバックできます。このヘッダーは、API バージョン 20.0 以降で使用できます。デフォルトの動作では、コールの部分的な成功を許可します。つまり、エラーのないレコードはコミットされますが、エラーのあったレコードはコールの結果では失敗とマークされます。
サンプルコード —Java
このサンプルでは、queryAll() をコールして、直近に削除された取引先を 5 つ取得します。次に、これらの取引先の ID を undelete() に渡し、これらの取引先を復元します。最後に、コールの結果を確認して、復元された取引先の ID またはエラーをコンソールに書き込みます。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void undeleteRecords() {
18 try {
19 // Get the accounts that were last deleted
20 // (up to 5 accounts)
21 QueryResult qResult = connection
22 .queryAll("SELECT Id, SystemModstamp FROM "
23 + "Account WHERE IsDeleted=true "
24 + "ORDER BY SystemModstamp DESC LIMIT 5");
25
26 String[] Ids = new String[qResult.getSize()];
27 // Get the IDs of the deleted records
28 for (int i = 0; i < qResult.getSize(); i++) {
29 Ids[i] = qResult.getRecords()[i].getId();
30 }
31
32 // Restore the records
33 UndeleteResult[] undelResults = connection.undelete(Ids);
34
35 // Check the results
36 for (UndeleteResult result : undelResults) {
37 if (result.isSuccess()) {
38 System.out.println("Undeleted Account ID: " + result.getId());
39 } else {
40 if (result.getErrors().length > 0) {
41 System.out.println("Error message: "
42 + result.getErrors()[0].getMessage());
43 }
44 }
45 }
46 } catch (ConnectionException ce) {
47 ce.printStackTrace();
48 }
49}サンプルコード —C#
このサンプルでは、queryAll() をコールして、直近に削除された取引先を 5 つ取得します。次に、これらの取引先の ID を undelete() に渡し、これらの取引先を復元します。最後に、コールの結果を確認して、復元された取引先の ID またはエラーをコンソールに書き込みます。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void undeleteRecords()
18{
19 try
20 {
21 // Get the accounts that were last deleted
22 // (up to 5 accounts)
23 QueryResult qResult = binding.queryAll(
24 "SELECT Id, SystemModstamp FROM " +
25 "Account WHERE IsDeleted=true " +
26 "ORDER BY SystemModstamp DESC LIMIT 5");
27
28 String[] Ids = new String[qResult.size];
29 // Get the IDs of the deleted records
30 for (int i = 0; i < qResult.size; i++)
31 {
32 Ids[i] = qResult.records[i].Id;
33 }
34
35 // Restore the records
36 UndeleteResult[] undelResults = binding.undelete(Ids);
37
38 // Check the results
39 foreach (UndeleteResult result in undelResults)
40 {
41 if (result.success)
42 {
43 Console.WriteLine("Undeleted Account ID: " +
44 result.id);
45 }
46 else
47 {
48 if (result.errors.Length > 0)
49 {
50 Console.WriteLine("Error message: " +
51 result.errors[0].message);
52 }
53 }
54 }
55 }
56 catch (SoapException e)
57 {
58 Console.WriteLine("An unexpected error has occurred: " +
59 e.Message + "\n" + e.StackTrace);
60 }
61}引数
| 名前 | 型 | 説明 |
|---|---|---|
| ids | ID[] | 復元するレコードの ID。 |