When to use saveRecord() vs. updateRecord()
When to use saveRecord() vs. updateRecord()
Notice the different behaviors for
updateRecord(record
) and
saveRecord(record)
.
updateRecord(record) | saveRecord(record) |
---|---|
Inserts new or updates an existing record. If a record with specified primary key value already exists, then updates the record. If not, adds a new record. | Inserts new or updates existing record. The client passes the old (unchanged) field values, so that if the primary key values are changed by the user, system can still find and update the same record. |
Does NOT depend on
record.isNew()
value to generate UPDATE or INSERT like
saveRecord
does.
|
Does depend on
record.isNew()
value to generate UPDATE or INSERT
|
You CANNOT update a primary key if the new primary key doesn’t exist. It will just add a new record. | You CAN update a primary key if the new primary key doesn’t exist. |