sforce logo

update


Updates one or more existing objects in your organization's data.

Syntax

SaveResult[] = sfdc.update(sObject[] sObjects); 

Usage

Use update 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.

Rules and Guidelines

When updating objects, consider the following rules and guidelines:

Permissions

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.

Special Handling

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 Chapter 5: sforce Objects.

Updateable Objects

Certain objects cannot be updated via the sforce API. To update an object via the update call, its object must be configured as updateable (updateable=True). To determine whether an object can be updated, your client application can invoke the describeSObject call on the object and inspect its updateable property.

Required Fields

When updating required fields, you must supply a value-you cannot set the value to null. For more information, see Required Fields.

ID Fields

You cannot update fields with "Id" in the name, such as reference fields that point to other objects (for example, CaseId or OpportunityId). Such fields are analogous to a primary or foreign key field in SQL databases.

Automatically Updated Fields

The sforce Web service updates certain fields automatically, such as LastModifiedDate, LastModifiedById, and SystemModstamp. You cannot explicitly specify these values in your update call.

Resetting Values to null

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=false) to null.

Valid Field Values

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).

String Values

When storing values in string fields, the sforce Web service trims any leading and trailing whitespace. 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".

Assignment Rules

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.com user interface. For more information, see Case or Lead.

Maximum Number of Objects Created.

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.

Basic Steps for Updating Objects

Updating objects involves the following basic steps:

  1. Determine the ID of each object that you want to update. For example, you might call query to retrieve a set of objects (with their IDs), based on specific criteria, that you would want to update. If you know the ID of the object that you want to update, you can call retrieve instead.
  2. For each object, populate its fields with the data that you want to update.
  3. Construct an sObject[] array and populate that array with the objects that you want to update. All objects must be of the same object.
  4. Call update, passing in the sObject[] array.
  5. Process the results in the SaveResult[] object to verify whether the objects have been successfully updated.

Sample Code-Java

public void updateAccountSample() { 
 
   // Create an array of SObjects to send to the update method 
   SObject[] updates = new SObject[2]; 
 
   // This account could also be from the results of a retrieve or query call 
   Account updateAccount = new Account(); 
   updateAccount.setId(new ID("001x00000000JerAAE")); 
   updateAccount.setName("New Account Name from Update Sample"); 
   updates[0] = updateAccount; 
 
   Account updateAccount2 = new Account(); 
   updateAccount2 = new Account(); 
   updateAccount2.setId(new ID("001x00000000JesAAE")); 
   updateAccount2.setWebsite("www.website.com"); 
   updates[1] = updateAccount2; 
 
   // Invoke the update call and save the results 
   SaveResult[] saveResults = binding.update(updates); 
   print("\nPress the RETURN key to continue...", false); 
} 

Sample Code-C#

private void update() 
{ 
   // You would typically retrieve an SObject, modify its properties, 
   // and then send the objects up in an array. For this sample, 
   // we create a new contact object to update by setting  
   // the id to a valid contact id 
   Contact contact = new Contact(); 
   contact.Id = "";  // This should be a valid ID 
   contact.MailingCity = "new city"; 
   contact.MailingPostalCode = "98776"; 
 
  // Invoke the update call, saving the results in SaveResult 
   SaveResult[] sr = binding.update(new sObject[]{contact}); 
 
   // The SaveResult should never be empty 
   for (int i=0;i<sr.Length;i++)  
   { 
      // Determine whether the row update succeeded 
      if (sr[i].success)  
      { 
         // Get the ID of the updated row 
   System.Diagnostics.Trace.WriteLine(sr[i].id); 
      }  
      else  
      { 
         // Iterate through the errors 
         Error[] errors = sr[i].errors; 
         for (int j=0;j<errors.Length;j++) 
         { 
            System.Diagnostics.Trace.WriteLine(errors[j].message); 
         } 
      } 
   } 
}  

Arguments

Name
Type
Description
sObjects
Array of one or more objects (maximum of 200) to update. sforce Web service updates these objects in array index order.

Response

SaveResult[]

Fault

InvalidSObjectFault

UnexpectedErrorFault

See Also

Sample SOAP Messages-update

Concepts


© Copyright 2000-2003 SalesForce.com, Inc.
All rights reserved • Various trademarks held by their respective owners.