You are here:
upsert Function
Creates and updates records for the specified objects and returns results to the specified callback method.
Required Editions
| Available in: Lightning Experience |
| Available in: Enterprise and Unlimited Editions with Life Sciences Cloud, Life Sciences Cloud for Customer Engagement Add-on license, and the Life Sciences Customer Engagement managed package. |
This function is supported only in the Life Sciences Cloud mobile app.
You can create or update custom objects and supported Life Sciences Customer Engagement objects. To create or update records:
- The user must have Read permissions on the specified objects and fields.
- Active object metadata cache configurations must be created for each object and synced to the Life Sciences Cloud mobile app.
In the current release, you can use the upsert function to track interactions
within individual presentation pages, such as button clicks. Use a custom object to store the
page-level presentation metrics for reporting or processing.
Syntax
PresentationPlayer.upsert(objects, callbackMethod)Arguments
| Argument | Description |
|---|---|
objects |
An array of objects to create or update records for.
|
callbackMethod |
The name of the JavaScript method that receives the result of the operation. |
Returns
This function returns an array of IDs of the new or updated records.
Limitations
This function can’t create or update User, Record Type, Territory, Territory2, and UserTerritory2Association records.
You can’t use this function to create or update related records. To update related records, such as records in a parent-child relationship, use two function calls.
Example
This example creates records by using the object name.
<body>
<input id="name" style="color: black;">
<input id="customField" style="color: black;">
<a href="javascript:save();">Save Record</a>
</body>
<script type="text/javascript">
function save() {
let name = document.getElementById("name").value;
let customField= document.getElementById("customField").value;
PresentationPlayer.upsert([{
'sobject': 'Account',
'name': name,
'customField__c': customField
}], 'upsertCallbackMethod');
}
function upsertCallbackMethod(data) {
console.log(data);
PresentationPlayer.alert(JSON.stringify(data));
}
</script>This example updates records by using record IDs.
<script type="text/javascript">
function save() {
let name = document.getElementById("name").value;
let customField= document.getElementById("customField").value;
let accountId = allData.customers[0].Id;
PresentationPlayer.upsert([{
'sobject': 'Account',
'id': accountId,
'name': name,
'customField__c': customField
}], 'upsertCallbackMethod');
}
function upsertCallbackMethod(data) {
if (data.state === 'success') {
console.log(data);
PresentationPlayer.alert(JSON.stringify(data));
} else {
PresentationPlayer.alert(data.message + '\n' + data.code);
}
}
</script>Errors
This function processes up to 15 records at a time. If you submit more than 15 records, an error occurs.
This function can also return errors if there are failures when creating or updating records. For example, errors can occur when:
- Validation rules fail.
- The user doesn’t have Read or Edit access to the object or field.
- The object or field isn’t supported.
- SQLite database query errors occur.

