getAppViewInfo() for Lightning Experience

Usage 

Returns information about the current application view. This method is available in API version 38.0 or later.

Syntax 

1sforce.opencti.getAppViewInfo({
2     callback: FUNCTION
3});

Arguments 

NameTypeDescription
callbackfunctionJavaScript method executed when the API method call is completed.

Sample Code–HTML and JavaScript 

1<html>
2  <head>
3    <script type="text/javascript" src="https://domain:port/support/api//lightning/opencti_min.js"></script>
4    <script type="text/javascript">
5      var callback = function(response) {
6         if (response.success) {
7            console.log('API method call executed successfully! returnValue:', response.returnValue);
8         } else { 
9            console.error('Something went wrong! Errors:', response.errors);
10         } 
11      };
12
13      function getAppViewInfo() {
14          sforce.opencti.getAppViewInfo({callback: callback});
15      }
16     </script>
17  </head>
18  <body>
19    <button onclick="getAppViewInfo();">getAppViewInfo()</button>
20  </body>
21</html>

Response 

This method is asynchronous. The response is returned in an object passed to a callback method.

When you switch from a record detail page to a list view, this method returns:

  • In Lightning Experience, only the url

  • In Lightning Experience console apps, nothing is returned because the listener isn’t invoked

  • success (boolean)

    • : Returns true if the API method call was invoked successfully, false otherwise.

  • returnValue (object)

    • : Returns the URL of the current application view and includes any applicable record ID, record name, and object type. For example:

      1{
      2    "url": "https://MYDOMAINNAMEmy.salesforce.com/lightning/r/Case/500D0000003tcchIAA/view?t=1459806689555",
      3    "recordId": "001x0000003DGQR",
      4    "recordName": "Acme",
      5    "objectType": "Account"
      6}

      Invoking this API method on a person account object returns the following additional information.

      • accountId or contactId—The associated account or contact ID.
      • personAccount—Which is true if person accounts are enabled in your org, false otherwise.

      For example:

      1{
      2    "url": "https://MYDOMAINNAMEmy.salesforce.com/lightning/r/Account/001x0000003DGQR/view",
      3    "recordId": "001x0000003DGQR",
      4    "recordName": "Acme Person Account",
      5    "objectType": "Account",
      6    "contactId": "003D000000QOMqg",
      7    "personAccount": true
      8}

      Since the URL structure of the returnValue can change in the future, we recommend that you don’t build any logic based on it.

  • error (array)

    • : If the API call was successful, this variable is null. If the API call failed, this variable returns an array of error messages.