Updates one or more existing objects in your organization’s data.
SaveResult[] = sfdc.update(sObject[] sObjects);
Use this call to update one or more existing objects, such as individual accounts or contacts, in your organization’s data. The update() call is analogous to the UPDATE statement in SQL.
Your client application must be logged in with sufficient access rights to update() individual objects (as well as individual fields inside that object) within the specified object. For more information, see Factors that Affect Data Access.
Certain objects—and certain fields within those objects—require special handling or permissions. For example, you might also need permissions to access this object’s parent object. Before you attempt to update a particular object, be sure to read its description in the Standard Objects and in the Salesforce online help.
Certain objects cannot be updated via the API. To update an object via the update() call, its object must be configured as updateable (updateable is true). To determine whether an object can be updated, your client application can invoke the describeSObjects() call on the object and inspect its updateable property.
When updating required fields, you must supply a value—you cannot set the value to null. For more information, see Required Fields.
Fields whose names contain “Id” are either that object’s primary key (see ID Field Type ) or a foreign key (see Reference Field Type ). Client applications cannot update primary keys, but they can update foreign keys. For example, a client application can update the OwnerId of an Account, because OwnerID is a foreign key that refers to the user who owns the account record. Use describeSObjects() to confirm whether the field can be updated.
Maximum number of duplicate updates in one batch (5 allowed). Attempt to update Id more than once in this API call: number_of_attempts.
The API updates certain fields automatically, such as LastModifiedDate, LastModifiedById, and SystemModstamp. You cannot explicitly specify these values in your update() call.
To reset a field value to null, you add the field name to the fieldsToNull array in the sObject. You cannot set required fields (nillable is false) to null.
You must supply values that are valid for the field’s data type, such as integers (not alphabetic characters) for integer fields. In your client application, follow the data formatting rules specified for your programming language and development tool (your development tool will handle the appropriate mapping of data types in SOAP messages).
When storing values in string fields, the API trims any leading and trailing white space. For example, if the value of a name field is entered as " ABC Company ", then the value is stored in the database as "ABC Company".
When updating Case or Lead objects, your client application can set AssignmentRuleHeader options to have the case or lead automatically assigned to one or more users based on assignment rules configured in the Salesforce user interface. For more information, see Case or Lead.
Your client application can change up to 200 individual objects in a single update() call. If an update request exceeds 200 objects, then the entire operation fails.
You can use external ID fields as a foreign key, allowing you to create, update, or upsert records in a single step instead of querying a record to get the ID first. To do this, specify the foreign key name and the external ID field value. For example:
Opportunity updateOpportunity = new Opportunity();
updateOpportunity.setStageName("Prospecting");
updateOpportunity.setId("006300000023YFu");
// Standard object ref
Account updateParentAccountRef = new Account();
updateParentAccountRef.setExternal_SAP1_ACCTID__c("SAP111111");
updateOpportunity.setAccount(updateParentAccount);
// call update
UpdateResult[] updateResults = binding.update(new SObject[] {updateOpportunity});
public void updateAccountSample() {
// Create an array of SObjects to send to the update method
Account[] updates = new Account[2];
// This account could also be from the results of a retrieve or query call
Account updateAccount = new Account();
updateAccount.setId("001x0000002kuk2AAA");
updateAccount.setShippingPostalCode("94105");
updates[0] = updateAccount;
Account updateAccount2 = new Account();
updateAccount2.setId("001x0000002kuk1AAA");
updateAccount2.setWebsite("www.website.com");
updates[1] = updateAccount2;
// Invoke the update call and save the results
try {
SaveResult[] saveResults = binding.update(updates);
}
catch (Exception ex) {
System.out.println("An unexpected error has occurred." + ex.getMessage());
getUserInput ("\nUpdate failed. Press return to continue...");
return;
}
getUserInput ("\nUpdate done. Press return to continue...");
}
using System;
using System.Collections.Generic;
using System.Text;
using SFDCWsdl.Salesforce_WSDL;
namespace SFDCWsdl
{
public class SFDCWsdlTest
{
private SforceService binding;
private static readonly string Username = "USERNAME";
private static readonly string Password = "PASSWORD";
/// <summary>
/// Create the binding and login
/// </summary>
private SFDCWsdlTest()
{
this.binding = new SforceService();
binding.login(SFDCWsdlTest.Username, SFDCWsdlTest.Password);
}
private void UpdateAccountSample()
{
//create the account object to hold our changes
sObject updateAccount = new sObject();
//need to have the id so that API knows which account to update
//set a new value for the name property
updateAccount.Id = "00130000001dmJT";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement nameElement = doc.GetElementById("Name");
nameElement.InnerText = "New Account Name from Update Sample";
updateAccount.Any = new System.Xml.XmlElement[] { nameElement };
updateAccount.type = "Account";
//call the update passing an array of object
SaveResult[] saveResults = binding.update(new sObject[] { updateAccount });
//loop through the results, checking for errors
for (int j = 0; j < saveResults.Length; j++)
{
Console.WriteLine("Item: " + j);
if (saveResults[j].success)
Console.WriteLine("An account with an id of: " + saveResults[j].id +
" was updated.\n");
else
{
Console.WriteLine("Item " + j.ToString() + " had an error updating.");
Console.WriteLine(" The error reported was: " +
saveResults[j].errors[0].message + "\n");
}
}
}
}
}
| Name | Type | Description |
|---|---|---|
| sObjects | sObject[] | Array of one or more objects (maximum of 200) to update. |