Changing the Search Result Links for Salesforce Items

When using Coveo for Salesforce, you will sometimes want to modify the result link of your Salesforce items. For example, you can have your Knowledge articles published on an external website, and want to have your search page redirect to your external articles over your internal one.

To achieve this, you need to change the URI of your Salesforce item. The solution explained on this page is client-side, meaning that it doesn’t change the way the Salesforce items are indexed in the Coveo Cloud.

Coveo for Salesforce 2.25 (July 2016)

When using Coveo for Salesforce 2.24 and under (before July 2016), you can only change the result link URI directly in the code using the Underscore library (see Using the Underscore Library).

Editing the Search Page Code

When editing the code, there are two ways to achieve the same result:

Using the Coveo JavaScript Search Framework

Coveo for Salesforce 2.25 (July 2016)

When using Coveo for Salesforce July 2016 or newer (2.25+), you’re strongly encouraged to use this method instead of using Underscore templates.

  1. Access the code of the search page or search component you want to change.

    1. In Setup, search for and access the Visualforce Components page.

    2. Find the search page you want to change, and under Actions, select Edit.

  2. In your search page code, find the result template of the item you want to change. It should be part of the following div: <div class="CoveoResultList">

    • Result templates are written in a <script> tag, inside of which is presented all of the HTML script for the result template.

    • Your item may use the default result template. For this tutorial to work, you must create a different result template that applies only to Knowledge articles.

  3. Find one of the following sections of your result template:

    • <span class="CoveoSalesforceResultLink">

    • <a class="CoveoConsoleResultLink">

    If you can’t find it, you may need to add it at the location you want your result link to be (see SalesforceResultLink Component and ConsoleResultLink Component).

    Ensure that your component has only one Coveo class. Having many Coveo classes on your component may result in unexpected behavior.

  4. If not already the case, replace the CoveoSalesforceResultLink component by the CoveoConsoleResultLink component.

  5. Inside the <a> element, add the following reference:

     data-href-template="<YOUR_EXTERNAL_URL>/${<YOUR_FIELD>}"
    

    Where you replace:

    • <YOUR_EXTERNAL_URL> by the external URL where you want user to be redirected.

    • <YOUR_FIELD> by the name of the field you want to append to the URL.

    For more information on the hrefTemplate component option, see hrefTemplate.

    You want to redirect your Knowledge articles to the external website https://www.external.com, where all the Salesforce articles are available by appending the article number to the URL. Out of the box, this number is already associated to the sfkbarticlenumber field in the index.

    Your span element should look like this:

     <a class="CoveoConsoleResultLink" data-href-template="https://www.external.com/${raw.sfkbarticlenumber}"></a>
    

    The reason you’re entering raw before sfkbarticlenumber is that you’re adding a field generated in the Coveo index.

    When adding Salesforce fields, such as title, you only need to enter ${title}.

  6. Save your page.

  7. Verify that your redirection works as expected by accessing your search page and clicking on the result link of your item.

Using the Underscore Library

Using the Underscore library may prevent you from using the Interface Editor. It’s also not Lightning Locker compliant (see Making the Coveo Lightning Components Lightning Locker Compliant).

However, when using Coveo for Salesforce prior to the July 2016 release (2.24 or under), you should use this option.

  1. Access the code of the search page or search component you want to change.

    1. In Setup, search for and access the Visualforce Components page.

    2. Find the search page you want to change, and under Actions, click on Edit.

  2. Find the result template of the item you want to change. It should be part of the following div: <div class="CoveoResultList">

    • Result templates are written in a <script> tag, inside of which is presented all of the HTML script for the result template.

    • Your item may use the default result template. For this tutorial to work, we recommend that you create a different result template that applies only to Knowledge articles. For more information, see JavaScript Search Framework Result Templates.

  3. In the script tag, add/modify the text to use the Underscore library.

    <script id="<YOUR_ID>" class="result-template" type="text/underscore">
    

    Where your replace <YOUR_ID> by he name of your result template.

  4. Find one of the following sections of your result template:

    • <a class="CoveoSalesforceResultLink">

    • <a class="CoveoConsoleResultLink">

    If you can’t find it, you may need to add it at the location you want your result link to be (see SalesforceResultLink Component and ConsoleResultLink Component).

    Ensure that your component has only one Coveo class. Having many Coveo classes on your component may result in unexpected behavior.

  5. If not already the case, replace the CoveoSalesforceResultLink component by the CoveoConsoleResultLink component.

  6. Inside the <a> element, add the following reference:

     href="<YOUR_EXTERNAL_URL>/<%= <YOUR_FIELD>%>"
    

    Where you replace:

    • <YOUR_EXTERNAL_URL> by the external URL where you want user to be redirected.

    • <YOUR_FIELD> by the name of the field you want to append to the URL.

    You want to redirect your Knowledge articles to the external website https://www.external.com, where all the Salesforce articles are available by appending the article number to the URL. Out of the box, this number is already associated to the sfkbarticlenumber field in the index.

    Your span element should look like this:

     <a class="CoveoConsoleResultLink" data-href-template="https://www.external.com/<%= raw.sfkbarticlenumber%>"></a>
    

    The reason you’re entering raw before sfkbarticlenumber is that you’re adding a field generated in the Coveo index.

    When adding Salesforce fields, such as title, you only need to enter <%= title%>.

  7. Save your page.

  8. Verify that your redirection works as expected by accessing your search page and clicking on the result link of your item.

What's Next for Me?