We have a SOSL query that is searching multiple custom objects. The desired result is one search result pane that shows results from the multiple tables in one list. Because multiple custom objects are involved, I have had to create 'If' statements to inspect the results to ensure that the results are formatted properly. For the most part, the results are as desired by the solution architect.
However, there is a problem that I am having because the original architect has named some of the field names the same across multiple custom objects and they don't want them changed.
I will admit that I am very much a rookie when it comes to Salesforce Lightning custom objects (this is my first one) so I acknowledge the fact that there is probably a better way to do this. I would welcome input on how to fix my code to avoid the false duplicates through maybe more efficient SOSL Query and rendering code, or a way to stipulate which Custom object I am inspecting for specific fields. In our case, the 'OCS_Investigation' custom object has an 'Agent_First_name__c' and 'Agent_Last_Name__c' fields and the 'Participating_Agents__c' table also has the same field names. My suggestion to change the custom object field names to be unique has met with significant resistance because I am not the one responsible for the project.
Here is my SOSL Query:
public class OCS_Search_Controller {
@AuraEnabled
public static List<String> searchForIds(String searchText) {
System.debug('The value of searchText is: '+ searchText);
List<String> ids = new List<String>(); //This code creates the holder for the found ids.
List<String> Creator = new List<String>();
//The following code will look for matches in the OCS_Investigation__c object for the search argument entered.
List<List<SObject>> results1 = [FIND :searchText IN ALL FIELDS RETURNING OCS_Investigation__c(Name), Evidence__c(Name), Participating_Agents__c(Name), Property_Damage__c(Name), Subject__c(Name), Case_Chronology__c(Name), ContentVersion(title), ContentVersion(CreatedDate)];
for (List<SObject> sobjs1 : results1) {
for (SObject sobj1 : sobjs1) {
ids.add(sobj1.Id);
}
}
return ids;
}
}
Here is the Code for the component that renders the results:
<aura:component implements="force:hasRecordId" access="global">
<aura:attribute name="record" type="Object"/>
<aura:attribute name="simpleRecord" type="Object"/>
<aura:attribute name="recordError" type="String"/>
<force:recordData aura:id="recordLoader"
recordId="{!v.recordId}"
layoutType="FULL"
targetRecord="{!v.record}"
targetFields="{!v.simpleRecord}"
targetError="{!v.recordError}" />
<!-- Display a header with details about the Investigation record -->
<aura:if isTrue="{!not(empty(v.simpleRecord.Type_of_Investigation__c))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Investigation Case id: {!v.simpleRecord.Name} <br/> Agent Name: {!v.simpleRecord.Agent_First_Name__c}_{!v.simpleRecord.Agent_Last_Name__c} <br/> Case Title: {!v.simpleRecord.Case_Title__c}</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display a header with details about the Chronology record -->
<aura:if isTrue="{!not(empty(v.simpleRecord.Activity__c))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Chronology Entry id: {!v.simpleRecord.Name} <br/> Activity Agent Name: {!v.simpleRecord.Activity_Agent_First_Name__c}_{!v.simpleRecord.Activity_Agent_Last_Name__c}</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display a header with details about the Evidence record -->
<aura:if isTrue="{!not(empty(v.simpleRecord.Evidence_Record_Status__c))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Evidence entry id: {!v.simpleRecord.Name} <br/> Evidence Type: {!v.simpleRecord.Type_of_Evidence__c}</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display a header with details about the Participating Agent record -->
<aura:if isTrue="{!not(empty(v.simpleRecord.Participating_Agents__c.Name))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Participating Agent entry id: {!v.simpleRecord.Name} <br/> Agent Name: {!v.simpleRecord.Agent_First_Name__c}_{!v.simpleRecord.Agent_Last_Name__c}</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display a header with details about the Subject record -->
<aura:if isTrue="{!not(empty(v.simpleRecord.Type_of_Subject__c))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Subject entry id: {!v.simpleRecord.Name} <br/> Subject Type: {!v.simpleRecord.Type_of_Subject__c} <br/> Subject Name: {!v.simpleRecord.First_Name__c} _ {!v.simpleRecord.Last_Name__c}</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display a header with details about the Property Damage record -->
<aura:if isTrue="{!not(empty(v.simpleRecord.Property_Description__c))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Property Damage entry id: {!v.simpleRecord.Name} <br/> Control Form Provided: {!v.simpleRecord.CA_Board_of_Control_Form_Provided__c}</p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display a header with details about the Attachment record -->
<aura:if isTrue="{!(empty(v.simpleRecord.Name))}">
<div class="slds-page-header" role="banner">
<p class="slds-text-heading--label">Attachement Title: {!v.simpleRecord.Title} <br/> Checksum: {!v.SimpleRecord.Checksum} <br/> ContentModifiedById: {!v.SimpleRecord.ContentModifiedById} <br/> ContentModifiedDate: {!v.SimpleRecord.ContentModifiedDate} <br/> Origin: {!v.SimpleRecord.Origin} <br/> ContentUrl: {!v.SimpleRecord.ContentUrl} <br/> Id: {!v.SimpleRecord.Id} <br/> CreatedById: {!v.SimpleRecord.CreatedById} <br/> CreatedByDate: {!v.SimpleRecord.CreatedByDate} <br/> Description: {!v.SimpleRecord.Description} <br/> ContentDocumentId: {!v.SimpleRecord.ContentDocumentId} <br/> ExternalDataSourceId: {!v.SimpleRecord.ExternalDataSourceId} <br/> ExternalDocumentInfo1: {!v.SimpleRecord.ExternalDocumentInfo1} <br/> ExternalDocumentInfo2: {!v.SimpleRecord.ExternalDocumentInfo2} <br/> FeaturedContentBoost: {!v.SimpleRecord.FeaturedContentBoost} <br/> FeaturedContentDate: {!v.SimpleRecord.FeaturedContentDate} <br/> FileExtension: {!v.SimpleRecord.FileExtension} <br/> FileType: {!v.SimpleRecord.FileType} <br/> FirstPublishedLocationId: {!v.SimpleRecord.FirstPublishedLocationId} <br/> IsDeleted: {!v.SimpleRecord.IsDeleted} <br/> IsLatest: {!v.SimpleRecord.IsLatest} <br/> LastModifiedById: {!v.SimpleRecord.LastModifiedById} <br/> LastModifiedDate: {!v.SimpleRecord.LastModifiedDate} <br/> IsMajorVersion: {!v.SimpleRecord.IsMajorVersion} <br/> NegativeRatingCount: {!v.SimpleRecord.NegativeRatingCount} <br/> OwnerId: {!v.SimpleRecord.OwnerId} <br/> PathOnClient: {!v.SimpleRecord.PathOnClient} <br/> PositiveRatingCount: {!v.SimpleRecord.PositiveRatingCount} <br/> PublishStatus: {!v.SimpleRecord.PublishStatus} <br/> RatingCount: {!v.SimpleRecord.RatingCount} <br/> ReasonForChange: {!v.SimpleRecord.ReasonForChange} <br/> ContentSize: {!v.SimpleRecord.ContentSize} <br/> SystemModStamp: {!v.SimpleRecord.SystemModStamp} <br/> TagCsv: {!v.SimpleRecord.TagCsv} <br/> VersionData: {!v.SimpleRecord.VersionData} <br/> VersionNumber: {!v.SimpleRecord.VersionNumber} <br/></p>
<h1 class="slds-page-header__title slds-m-right--small slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/one/one.app?source=alohaHeader#/sObject/' + v.simpleRecord.Id}">Go to details</a></h1>
</div>
</aura:if>
<!-- Display Lightning Data Service errors, if any -->
<!-- <aura:if isTrue="{!not(empty(v.recordError))}">
<div class="recordError">
<ui:message title="Error" severity="error" closable="true">
{!v.recordError}
</ui:message>
</div>
</aura:if> -->
</aura:component>