Change the search result links for Salesforce items
Change 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 site, 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 Coveo.
Editing the search page code
When editing the code, we recommend using the Coveo JavaScript Search Framework.
Using the Coveo JavaScript Search Framework
-
Access the code of the search page or search component you want to change.
-
In Setup, search for and access the Visualforce Components page.
-
Find the search page you want to change, and under Actions, select Edit.
-
-
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">
Notes-
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.
-
-
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 andConsoleResultLink
component).ImportantEnsure that your component has only one Coveo class. Having many Coveo classes on your component may result in unexpected behavior.
-
-
If not already the case, replace the
CoveoSalesforceResultLink
component by theCoveoConsoleResultLink
component. -
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.NoteFor more information on the
hrefTemplate
component option, see hrefTemplate.
ExampleYou 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 thesfkbarticlenumber
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
beforesfkbarticlenumber
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}
. -
-
Save your page.
-
Verify that your redirection works as expected by accessing your search page and clicking the result link of your item.