Created
November 19, 2015 06:20
-
-
Save tyoshikawa1106/06a40245373ae7fc27f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String createSample() { | |
String result = null; | |
try { | |
// Create a new sObject of type Contact | |
// and fill out its fields. | |
SObject contact = new SObject(); | |
contact.setType("Contact"); | |
contact.setField("FirstName", "Otto"); | |
contact.setField("LastName", "Jespersen"); | |
contact.setField("Salutation", "Professor"); | |
contact.setField("Phone", "(999) 555-1234"); | |
contact.setField("Title", "Philologist"); | |
// Add this sObject to an array | |
SObject[] contacts = new SObject[1]; | |
contacts[0] = contact; | |
// Make a create call and pass it the array of sObjects | |
SaveResult[] results = partnerConnection.create(contacts); | |
// Iterate through the results list | |
// and write the ID of the new sObject | |
// or the errors if the object creation failed. | |
// In this case, we only have one result | |
// since we created one contact. | |
for (int j = 0; j < results.length; j++) { | |
if (results[j].isSuccess()) { | |
result = results[j].getId(); | |
System.out.println( | |
"\nA contact was created with an ID of: " + result | |
); | |
} else { | |
// There were errors during the create call, | |
// go through the errors array and write | |
// them to the console | |
for (int i = 0; i < results[j].getErrors().length; i++) { | |
Error err = results[j].getErrors()[i]; | |
System.out.println("Errors were found on item " + j); | |
System.out.println("Error code: " + | |
err.getStatusCode().toString()); | |
System.out.println("Error message: " + err.getMessage()); | |
} | |
} | |
} | |
} catch (ConnectionException ce) { | |
ce.printStackTrace(); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://resources.docs.salesforce.com/198/0/ja-jp/sfdc/pdf/apex_api.pdf