1public 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}