No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
create コール例
次の Java および C# の例では、Partner WSDL の create() コールの使用方法を示します。各例では、複数の項目を持つ取引先責任者レコードを作成します。create コールの結果を反復処理し、操作が成功したかどうかを確認します。作成操作が成功した場合は、作成された取引先責任者の ID をコンソールに書き込みます。成功しなかった場合は、エラーを反復処理し、各エラーの詳細をコンソールに書き込みます。この例では、出力は新しい取引先責任者の ID です。
サンプルメソッドを実行するには、Partner WSDL の使用例で提供されている対応する Java または C# テンプレートクラスを使用できます。
Java の例
1swfobject.registerObject("clippy.codeblock-0", "9");public String createSample() {
2 String result = null;
3 try {
4 // Create a new sObject of type Contact
5 // and fill out its fields.
6 SObject contact = new SObject();
7 contact.setType("Contact");
8 contact.setField("FirstName", "Otto");
9 contact.setField("LastName", "Jespersen");
10 contact.setField("Salutation", "Professor");
11 contact.setField("Phone", "(999) 555-1234");
12 contact.setField("Title", "Philologist");
13
14 // Add this sObject to an array
15 SObject[] contacts = new SObject[1];
16 contacts[0] = contact;
17 // Make a create call and pass it the array of sObjects
18 SaveResult[] results = partnerConnection.create(contacts);
19
20 // Iterate through the results list
21 // and write the ID of the new sObject
22 // or the errors if the object creation failed.
23 // In this case, we only have one result
24 // since we created one contact.
25 for (int j = 0; j < results.length; j++) {
26 if (results[j].isSuccess()) {
27 result = results[j].getId();
28 System.out.println(
29 "\nA contact was created with an ID of: " + result
30 );
31 } else {
32 // There were errors during the create call,
33 // go through the errors array and write
34 // them to the console
35 for (int i = 0; i < results[j].getErrors().length; i++) {
36 Error err = results[j].getErrors()[i];
37 System.out.println("Errors were found on item " + j);
38 System.out.println("Error code: " +
39 err.getStatusCode().toString());
40 System.out.println("Error message: " + err.getMessage());
41 }
42 }
43 }
44 } catch (ConnectionException ce) {
45 ce.printStackTrace();
46 }
47 return result;
48}C# の例
1swfobject.registerObject("clippy.codeblock-1", "9");public void createSample()
2{
3 try
4 {
5 // Create a new sObject of type Contact
6 // and fill out its fields.
7 sObject contact = new sforce.sObject();
8 System.Xml.XmlElement[] contactFields = new System.Xml.XmlElement[6];
9
10 // Create the contact's fields
11 System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
12 contactFields[0] = doc.CreateElement("FirstName");
13 contactFields[0].InnerText = "Otto";
14 contactFields[1] = doc.CreateElement("LastName");
15 contactFields[1].InnerText = "Jespersen";
16 contactFields[2] = doc.CreateElement("Salutation");
17 contactFields[2].InnerText = "Professor";
18 contactFields[3] = doc.CreateElement("Phone");
19 contactFields[3].InnerText = "(999) 555-1234";
20 contactFields[4] = doc.CreateElement("Title");
21 contactFields[4].InnerText = "Philologist";
22
23 contact.type = "Contact";
24 contact.Any = contactFields;
25
26 // Add this sObject to an array
27 sObject[] contactList = new sObject[1];
28 contactList[0] = contact;
29
30 // Make a create call and pass it the array of sObjects
31 SaveResult[] results = binding.create(contactList);
32 // Iterate through the results list
33 // and write the ID of the new sObject
34 // or the errors if the object creation failed.
35 // In this case, we only have one result
36 // since we created one contact.
37 for (int j = 0; j < results.Length; j++)
38 {
39 if (results[j].success)
40 {
41 Console.Write("\nA contact was created with an ID of: "
42 + results[j].id);
43 }
44 else
45 {
46 // There were errors during the create call,
47 // go through the errors array and write
48 // them to the console
49 for (int i = 0; i < results[j].errors.Length; i++)
50 {
51 Error err = results[j].errors[i];
52 Console.WriteLine("Errors were found on item " + j.ToString());
53 Console.WriteLine("Error code is: " + err.statusCode.ToString());
54 Console.WriteLine("Error message: " + err.message);
55 }
56 }
57 }
58 }
59 catch (SoapException e)
60 {
61 Console.WriteLine("An unexpected error has occurred: " + e.Message +
62 " Stack trace: " + e.StackTrace);
63 }
64}