Migrating components from Salesforce API 39 to API 40+

Coveo for Salesforce 4.0 (April 2020)

As of the release of Coveo for Salesforce v4, the following components using Salesforce API 39 have been deleted in favour of newer, Lightning Locker compliant components.

All three of the newer components uses the SearchUI Lightning component to wrap the Coveo JavaScript Search Framework.

This nested component takes care of:

  • Loading your search page content

  • Initializing the Coveo JavaScript Search Framework

  • Providing customization options

This article provides guidelines to help you update these components without losing their current usability and customization.

Component Specifics

<aura:component implements='forceCommunity:availableForAllPageTypes'>
  <aura:attribute name="name" type="String" default="customCommunitySearch" access="global" />
  <CoveoV2:CommunitySearch name="{!v.name}" />
</aura:component>

At first glance, the new Community Search component’s behavior is very similar to the Search component you’re already using. However, under the hood, it uses the SearchUI Lightning component to wrap the Coveo JavaScript Search Framework. Several component attributes have been removed or replaced in favor of utilizing the hooks provided by SearchUI for passing data to the Coveo JavaScript Search Framework.

A few properties that were present on the designer view of the Coveo Search component have been removed. The following sections show how to migrate them.

autoInitialize

The default value was true, but users would usually set it to false to execute some custom logic before performing the Coveo JavaScript Search Framework initialization. The same result can now be achieved through the addPreInitPromise hook. This hook allows you to specify a JavaScript Promise containing your custom logic. Once this promise resolves, the Coveo JavaScript Search Framework will perform its initialization process.

autoInjectBasicQuery

The default value was true. If you set this property to false, then you probably want to override the executed query in some cases. To do so, you should register an event handler on the buildingQuery event.

  1. Register the event handler on buildingQuery using proxyAddEventListener.

  2. Implement your custom logic to override the query (see buildingQuery).

autoInjectBasicOptions

The default value was true. If you set this property to false, then you want to override the initialization options. To do so, you should rely on the setSearchInterfaceOptions method.

useAuraCache

This property isn’t available since the release of Salesforce API 44 (see Storable Actions).

loggerLevel

This property was used to control the traces logged from the Coveo JavaScript Search Framework in the browser console.

Level Value
TRACE 1
DEBUG 2
INFO 3
WARN 4
ERROR 5
NOTHING 6

With the new component you can specify a fixed logger level using a custom script.

window.coveoCustomScripts['default'] = function (promise) {
  const INFO = 3;
  Coveo.Logger.level = INFO;
}

searchContext

This property was used to send custom context information on the search queries. You can achieve the same result by using the buildingQuery event.

  1. Add an event handler on buildingQuery as specified in proxyAddEventListener.

  2. In the event handler, send the custom context information. In this example, we are sending a department name specified on the custom component. The contextual information can come from anywhere as long as your custom Lightning component has access to it.
     coveoSearchUI.proxyAddEventListener('buildingQuery', function(e, args) {
       const department = component.get('v.department');
       args.queryBuilder.addContext({
         'department': department
       });
     });
    
  3. You can validate that the contextual information is passed in Coveo by inspecting the HTTP request performed by the search page.

    1. Open your web browser developer tools. Select the Network tab.

    2. Navigate to your community page.

    3. Locate the POST request that targets https://platform.cloud.coveo.com/rest/search/v2.

    4. In the request body, you will find the context property with the custom information.

<aura:component implements='forceCommunity:searchInterface'>
  <CoveoV2:CommunitySearchBox/>
</aura:component>

The default component appears to look and behave like it’s predecessor. However, as mentioned above, it uses a SearchUI Lightning component to wrap the Coveo JavaScript Search Framework. Furthermore, several component attributes have been removed or replaced in favor of the hooks provided by the SearchUI for passing data to the Coveo JavaScript Search Framework.

Coveo Case Deflection

Following Salesforce’s Spring 18 release, the Lightning Create Case Form component was split into a Contact Support Form component and a Case Deflection component.

Click here for more details.

Coveo’s API 40+ equivalent to the Coveo CaseCreation Lightning component is a new Coveo Case Deflection component that replaces the aforementioned Case Deflection to work in conjunction with the Contact Support Form.

<aura:component implements='forceCommunity:availableForAllPageTypes'>
  <CoveoV2:CaseDeflection/>
</aura:component>

The following property doesn’t exist in the Case Deflection. The following section explains how to migrate it.

autoInjectBasicQuery

The default value was true. If you set this property to false, then you probably want to override the executed query in some cases. To do so, you should register an event handler on the buildingQuery event.

  1. Register the event handler on buildingQuery using proxyAddEventListener.

  2. Implement your custom logic to override the query (see buildingQuery).

Passing Data to the Coveo JavaScript Search Framework

The updated components expose a certain number of options you can set via their attributes. For options that have to do with the Coveo JavaScript Search Framework, you can access the component’s v.searchUI attribute. The many hooks it provides allow you to run custom code at specific points in the initialization lifecycle as well as pass context and other options to the underlying Coveo JavaScript Search Framework.

See the SearchUI Lightning component and Send custom context information pages for more details and examples.

Custom Scripts

If your customizations are for DOM manipulations, you can include custom scripts via static resource files in Salesforce as with the API 39 versions of the components.

See Add JavaScript to the Coveo for Salesforce Lightning components with custom code for more details on how to do so.

Custom Styling

As with the API 39 versions of the components, custom styling should be done directly in the wrapper component’s style sheet.