--- title: AttachToCaseController Apex class slug: p6bd0251 canonical_url: https://docs.coveo.com/en/p6bd0251/ collection: coveo-for-salesforce source_format: adoc --- # 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](https://docs.coveo.com/en/quantic/latest/usage/custom-ip-result-actions/) that allows users to attach search results to Cases or other records directly from a custom Coveo Quantic Insight Panel. ## Methods ### AttachToCase ```apex @AuraEnabled global static string AuraAttachToCase(string result) ``` Attaches a search result to a Salesforce record. **Parameters** * `result` (`String`): Stringified [`ResultToAttachArg`](#resulttoattacharg). The result object to attach. **Returns** `String`: JSON-serialized [`AttachToCaseResponse`](#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 ```apex @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`](#attachtocaseresponse). Response indicating success or failure. **Functionality** * Removes the corresponding attached result records. * For Cases, also removes the `CaseArticle` relationship if applicable. ### getAttachedResults ```apex @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`](#attachedresultsdetailed) object. **Functionality** * Queries both Coveo attached results and Knowledge Articles. * Returns detailed information for each attached result. ## Classes and data types [#resulttoattacharg] ### ResultToAttachArg Represents a search result to be attached to a record. [cols="1,1,3"] |=== |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` |Custom field values to store with the result |=== ### AttachToCaseResponse Response object for attach and detach operations. [cols="1,1,3"] |=== |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. [cols="1,1,3"] |=== |Property |Type |Description |`succeeded` |`Boolean` |Whether the retrieval operation completed successfully |`message` |`String` |Success message or error details |`attachedResults` |`List` |List of attached result identifiers |=== ### AttachedResultsDetailed Response object for retrieving detailed attached results information. [cols="1,1,3"] |=== |Property |Type |Description |`succeeded` |`Boolean` |Whether the retrieval operation completed successfully |`message` |`String` |Success message or error details |`attachedResults` |`List<[ResultToAttachArg](#resulttoattacharg)>` |List of detailed attached result objects |===