---
schema_version: "1"
id: b93177cf8c63d2e1f89120981b4ffb3071c95830a90f37afe449622699accf13
title: searchAndScreenPop() for Lightning Experience
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/api-cti/guides/sforce-api-cti-searchandscreenpop-lex.md
canonical_url: https://developer.salesforce.com/docs/service/api-cti/guide/sforce-api-cti-searchandscreenpop-lex.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b6efd68f5e04e896025006add425f3cb72735ba74a3eb430c19da5af82acba11
products:
  - Open CTI Developer Guide
  - Service Cloud Developer Content
---

# searchAndScreenPop() for Lightning Experience

## Usage

Searches objects specified in the softphone layout for a given string. Returns search results and screen pops any matching records. This method respects screen pop settings defined in the softphone layout. This method is available in API version 38.0 or later.

**note:** The returned response displays only matches that meet your softphone layout settings. However, the search page that screen pops, displays all matches, regardless of the objects you specify in your sofpthone layout.

The `searchAndScreenPop()` method for Lightning Experience works differently from the Salesforce Classic method.

- Open CTI for Lightning Experience doesn't support the softphone layout field `Screen pops open within` when the value is `New browser window or tab`. In Lightning Experience, the default value is `Existing browser window`.
- Open CTI for Lightning Experience provides a new argument called `deferred`.

**tip:** The `searchAndGetScreenPopUrl()` method is not available in the Open CTI API for Lightning Experience. To accomplish the same functionality in Lightning Experience, use the `deferred` parameter available in this method. Pass the value in `SCREEN_POP_DATA` from the return object into the `screenPop ()` method.

If you're noticing inconsistent behavior with the default settings of your softphone layout, edit your softphone layout to force the cache to refresh. From Setup, edit your softphone layout and save the changes. Then edit the layout again and reset the layout to the default settings.

## Syntax

```javascript
sforce.opencti.searchAndScreenPop({
     searchParams:STRING //Optional
     queryParams:STRING, //Optional
     defaultFieldValues:OBJECT, //Optional
     callType:sforce.opencti.CALL_TYPE.*, //Required. See arguments for more information.
     deferred:BOOLEAN //Optional)
     callback:FUNCTION //Optional
});

```

## Arguments

| Name                 | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| -------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `searchParams`       | string   | String to search.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `queryParams`        | string   | Specifies the query parameters to pass to the URL. Query parameters are only passed to the URL if the screen pop option is set to `Pop to Visualforce`.                                                                                                                                                                                                                                                                                                                                                                                                           |
| `params`             | object   | Specifies arguments to pass to a flow. `flowArgs` is a list of objects with key-value pairs containing information about the arguments being passed to the flow. Arguments must correspond to input variables of the specified name and type defined in the flow, else they are ignored. This argument can only be used with flows. Consult the FlowVariable section in [the topic on Flow](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_visual_workflow.htm) in the Metadata API Developer Guide for details on flow arguments. |
| `defaultFieldsValue` | object   | Optional. If you set up your softphone to pop to a new entity when there are no search results (for inbound calls), use this argument to specify the default fields for the screen pop. When the screen pop opens for the new entity, it's pre-populated with the fields you've specified.                                                                                                                                                                                                                                                                        |
| `callType`           | string   | Required. Specifies the type of call—inbound, outbound, internal, or null. Per the settings in the softphone layout, the call type determines which objects to search for any matches. Specify one of the following values: `sforce.opencti.CALL_TYPE.INBOUND`, `sforce.opencti.CALL_TYPE.OUTBOUND`, or `sforce.opencti.CALL_TYPE.INTERNAL`.                                                                                                                                                                                                                      |
| `deferred`           | boolean  | Specifies whether the screen pop is performed immediately following the search or deferred until later. Set to `false` (default) for an immediate screen pop. Set to `true` to defer. A JSON object is returned in the `SCREEN_POP_DATA` key, which must be passed unmodified to `sforce.opencti.screenPop` to perform the screen pop.                                                                                                                                                                                                                            |
| `callback`           | function | JavaScript method executed when the API method call is completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

Example `params` value:

```javascript
params: {
  FLOW: {
    flowArgs: [{ name: "YOUR_NAME", type: "YOUR_TYPE", value: "YOUR_VALUE" }];
  }
}
```

Example `defaultFieldsValue` call:

```javascript
{  searchParams: 'searchTermWithEmptyResults',
    callType: 'inbound',
    defaultFieldValues: {LastName : 'searchAndScreenPopLastName'},
    deferred: false,
    callback: function(result) {
        if (result.success) {
            console.log(result.returnValue);
        } else {
            console.log(result.errors);
        }
    }
```

## Sample Code–HTML and JavaScript

<!-- html set_clipboard -->

```html
<html>
  <head>
    <script
      type="text/javascript"
      src="http://domain:port/support/api//lightning/opencti_min.js"
    ></script>
    <script type="text/javascript">
      var callback = function (response) {
        if (response.success) {
          console.log("API method call executed successfully! returnValue:", response.returnValue);
        } else {
          console.error("Something went wrong! Errors:", response.errors);
        }
      };
      function searchAndScreenPop() {
        //Invokes API method
        sforce.opencti.searchAndScreenPop({
          searchParams: "Acme",
          queryParams: "Key1=value1&Key2=value2",
          callType: sforce.opencti.CALL_TYPE.INBOUND,
          deferred: false,
          callback: callback,
        });
      }
    </script>
  </head>
  <body>
    <button onclick="searchAndScreenPop();">searchAndScreenPop</button>
  </body>
</html>
```

## Response

| Name          | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `success`     | boolean | Returns `true` if the API method call was invoked successfully, `false` otherwise.                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `returnValue` | object  | Returns a list of objects that match the search results. The search is performed on the objects specified in the softphone layout. For each object found, the object ID, object type, last modified date, field names, and field values are returned as JSON objects. Make sure that you specify fields to return in your softphone layout. If you don't, nothing is returned. When invoked on an account or contact object, `AccountId` or `PersonContactId` and `IsPersonAccount` are also returned. |
| `errors`      | array   | If the API call was successful, this variable is `null`. If the API call failed, this variable returns an array of [error messages](https://developer.salesforce.com/docs/service/api-cti/guide/sforce-api-cti-error-messages-lightning.md).                                                                                                                                                                                                                                                                                                                       |

Example `returnValue` when searching for "Acme" (one Account and three Opportunity objects found):

```javascript
{
   "006x0000001ZcyG":{
    "Id": "006x0000001ZcyG"
    "LastModifiedDate": "2017-10-24T18:42:39.000Z",
    "Name":"Acme - 600 Widgets",
    "RecordType":"Opportunity"
   },
   "001x0000003DGQR":{
      "Name":"Acme",
      "Type":"Analyst",
      "object":"Account",
      "displayName":"Company"
   },
   "006x0000001ZcyH":{
      "Id": "006x0000001ZcyH"
      "LastModifiedDate": "2017-10-24T18:42:39.000Z",
      "Name":"Acme - 200 Widgets",
      "RecordType":"Opportunity"
   },
   "006x0000001ZcyF":{
      "Id": "006x0000001ZcyF"
      "LastModifiedDate": "2017-10-24T18:42:39.000Z",
      "Name":"Acme - 1,200 Widgets",
      "RecordType":"Opportunity"
   }
}
```

Example `returnValue` when using the `deferred` parameter (no screen navigation occurs):

```javascript
{
   "006x0000001ZcyG":{
       "Id": "006x0000001ZcyG"
       "LastModifiedDate": "2017-10-24T18:42:39.000Z",
       "Name":"Acme - 600 Widgets",
       "RecordType":"Opportunity"
   },
  SCREEN_POP_DATA : {} //an object. Do not modify it. Pass it to screenPop() API to navigate.
}
```

Example `returnValue` for an account or contact object (includes person account fields):

```javascript
{
   "006x0000001ZcyG":{
       "Id": "006x0000001ZcyG"
       "IsPersonAccount": true,
       "LastModifiedDate": "2017-11-15T00:10:47.000Z",
      "Name":"Acme Person Account",
    "PersonContactId" : "003D000000QOMqg",
      "RecordType":"Account"
   }
}
```
