AttachToCaseController Apex class

The AttachToCaseController Apex class provides methods to attach search results to Salesforce Cases and other records, detach them, and retrieve lists of attached results. This class supports both Coveo search results and Salesforce Knowledge Articles.

The typical use case is to create a custom Insight Panel result action that allows users to attach search results to Cases or other records directly from a custom Coveo Quantic Insight Panel.

Methods

AttachToCase

@AuraEnabled
global static string AuraAttachToCase(string result)

Attaches a search result to a Salesforce record.

Parameters

Returns

String: JSON-serialized AttachToCaseResponse. Response indicating success or failure.

Functionality

  • Creates or updates the appropriate attached result records.

  • For Knowledge Articles, also creates a CaseArticle relationship (Cases only).

DetachFromCase

@AuraEnabled
global static string AuraDetachFromCase(string uriHash, string sfkbid, string caseId)

Detaches a previously attached search result from a Salesforce record.

Parameters

  • uriHash (String): Permanent ID [or URI hash (deprecated)] of the result to detach.

  • sfkbid (String): Knowledge Article ID (for Knowledge Article detachment).

  • caseId (String): ID of the record to detach from.

Returns

String: JSON-serialized AttachToCaseResponse. Response indicating success or failure.

Functionality

  • Removes the corresponding attached result records.

  • For Cases, also removes the CaseArticle relationship if applicable.

getAttachedResults

@AuraEnabled
global static String getAttachedResults(Id caseId)

Retrieves all results attached to a specific record.

Parameters

  • caseId (Id): ID of the record to retrieve attached results for.

Returns

String: JSON-serialized AttachedResultsDetailed object.

Functionality

  • Queries both Coveo attached results and Knowledge Articles.

  • Returns detailed information for each attached result.

Classes and data types

ResultToAttachArg

Represents a search result to be attached to a record.

Property Type Description

caseId

String

ID of the Salesforce record to attach the result to

knowledgeArticleId

String

(Optional) ID of a Salesforce Knowledge Article

articleLanguage

String

(Optional) Language of the Knowledge Article

articleVersionNumber

Integer

(Optional) Version number of the Knowledge Article

articlePublishStatus

String

(Optional) Publication status of the Knowledge Article

uriHash

String

Unique hash identifier for the result URL

permanentId

String

Permanent identifier for the result

resultUrl

String

URL of the search result

source

String

Source system or content repository

title

String

Title of the search result

name

String

Display name for the attached result

customs

Map<String, String>

Custom field values to store with the result

AttachToCaseResponse

Response object for attach and detach operations.

Property Type Description

succeeded

Boolean

Whether the operation completed successfully

message

String

Success message or error details

AttachedResults

Response object for retrieving attached results lists.

Property Type Description

succeeded

Boolean

Whether the retrieval operation completed successfully

message

String

Success message or error details

attachedResults

List<String>

List of attached result identifiers

AttachedResultsDetailed

Response object for retrieving detailed attached results information.

Property Type Description

succeeded

Boolean

Whether the retrieval operation completed successfully

message

String

Success message or error details

attachedResults

List<ResultToAttachArg>

List of detailed attached result objects