Loading
Salesforce now sends email only from verified domains. Read More
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          upsert Function

          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.
          Note
          Note To use this function, log a request with Salesforce Support to allowlist the objects that you plan to upsert from the presentation content. For example, to update an account profile within the content, allowlist the Account object.

          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.

          • To create records, specify the object name.
          • To update records, specify the ID field that contains the ID or the offline ID.
          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.
           
          Loading
          Salesforce Help | Article