Loading
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
          fetchWithParams Function

          fetchWithParams Function

          Queries data that’s not already returned in Mustache variables, 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.

          You can query the User, Account, Record Type, Territory2, UserTerritory2Association, Life Sciences objects, and custom objects. To query records:

          • Assign Read permissions on the queried objects and fields to the user.
          • Create active object metadata cache configurations exist for each object and sync them to the Life Sciences Cloud mobile app.

          Syntax

          PresentationPlayer.fetchWithParams(query, params, callbackMethod)

          Arguments

          Argument Description
          query

          The SOQL query as a string, or the query locator value for subsequent fetches. You can include Mustache variables within queries.

          In the query parameter, specify these values.

          • object: The API name of the object.
          • fields: A comma-separated list of field API names.
          • where: Optional. A WHERE condition that references field API names.
          • order by: Optional. The field to order the query by.
          • limit: Optional. The maximum number of records to return.

          The WHERE clause supports:

          • These logical operators: AND, OR, NOT
          • These comparison operators: IN, LIKE, =, <, >

            To use the IN operator, surround values in brackets, for example, "Id IN {\”val1\”,\”val2\”}".

          • These SOQL keywords.
            • SELECT statements with column names, relations, and aggregate functions, but without subqueries
            • FROM statements with only one object name
            • GROUP BY columns or aggregate functions
            • HAVING statements
            • WHERE statements that support subqueries and literal sets
            • LIMIT and OFFSET functions
            • ORDER BY functions
          • These literals.
            • INT
            • FLOAT
            • STRING
            • NULL
            • BOOLEAN
          params

          Optional. The ability to specify the batch size.

          In the params argument, use the batchSize attribute to set the number of records to return in each call.

          Each call can return a maximum of 100 records.

          callbackMethod The name of the JavaScript method that receives the query results.

          Returns

          This function returns a JSON result.

          Field Name Type Description
          records Array<Object> The result data.
          done Boolean Indicates whether all data has been queried (true) or not (false).
          totalSize Integer The total number of records processed in the query.
          queryLocator String A unique SQL identifier that can be used in future requests.
          state String The request status, such as success or error.

          Usage

          Regardless of batch size, queries can return a maximum of 100 records. This example sets the batch size to 75 records.

          PresentationPlayer.fetchWithParams('SELECT FirstName, LastName, Name, Email, Phone, Username FROM User WHERE Id = ' + userId', {'batchSize': 75}, getCurrentUserRecordCallback');

          If you don't specify the batch size, the fetchWithParams function queries 15 records by default. To query additional records when using smaller batch sizes, use the queryLocator variable.

          This example uses the queryLocator variable.

          function getAccounts() {
                      PresentationPlayer.fetchWithParams('SELECT Id FROM Account', {'batchSize': 15}, 'getAccountsCallback');
              // Return 15 records
              }
              
              function getAccountsCallback(data) {
              // Process records
                      PresentationPlayer.fetchWithParams(data.queryLocator, 'getAccountsCallback');
              }

          Example

          <script type="text/javascript">
               var configData;
               document.addEventListener('PresentationDOMContentLoaded', function(event) => {
                   configData = event.data; 
                
                   function getCurrentUserRecord() {
                       let userId = ' \' ' + configData.parameters.id + ' \' ';
                       PresentationPlayer.fetchWithParams('SELECT FirstName, LastName, Name, Email, Phone, Username FROM User WHERE Id = ' + userId, {'batchSize': 75}, 
                        'getCurrentUserRecordCallback');
                   }
                   function getCurrentUserRecordCallback(data) {
                       if (data.state === 'success') {
                           const html = data.records.map((el)=>{
                               console.log('User Name: ', el.Name);
                               console.log('User Email: ', el.Email);
                         });
                       } else {
                           PresentationPlayer.alert(data.message + '\n' + data.code);
                       }
                   }
               </script>

          Errors

          This function returns an error when:

          • The query can’t access or find a record.
          • A SQL error occurs.
           
          Loading
          Salesforce Help | Article