You need to sign in to do that
Don't have an account?

Display Account,Contact & opportunity using sosl in lightning component
Hi,
I am trying to display Account, Contact & Opportunity using lightning component.
I am having 2 component one is searching and other is display. Stuck with displaying the records on the component with different tables for account,contact, and opportunity
public class CustomSearchController {
@AuraEnabled
public static getdata searchForIds(String searchText) {
getdata returndata = new getdata();
List<List<SObject>> results = [FIND :searchText IN ALL FIELDS RETURNING Account(Id,Name),Contact(Id,Name), Opportunity(Id,Name)];
Account[] accList = (Account[])results[0];
Contact[] conList = (Contact[])results[1];
Opportunity[] oppList = (Opportunity[])results[2];
returndata.acc = accList;
returndata.con = conList;
returndata.opp = oppList;
return returndata;
}
Public class getdata{
@AuraEnabled Public List<Account> acc {get;set;}
@AuraEnabled Public List<Contact> con {get;set;}
@AuraEnabled Public List<Opportunity> Opp {get;set;}
Public getdata(){}
}
}
----------------------------------------------------------------------------
SearchComponent
<aura:component implements="forceCommunity:searchInterface" >
<aura:attribute name="searchText" type="String" default=""/>
<aura:attribute name="disp" type="List"/>
<aura:registerEvent name="appEvent" type="c:appEvent"/>
<lightning:layoutItem size="3" padding="around-small">
<lightning:input value="{!v.searchText}" variant="brand" placeholder="Search" />
</lightning:layoutItem>
<lightning:layoutItem size="3" padding="around-small">
<lightning:button iconName="utility:search" variant="bare" label="Search" onclick="{! c.handleClick }" />
</lightning:layoutItem>
</aura:component>
--------------------------------------------------------------------
SearchComponentController
({
handleClick : function(component, event, helper) {
var searchbox = component.find("searchText").get("v.value");
var appEvent = $A.get("e.c:appEvent");
appEvent.setParams({"message": searchbox});
appEvent.fire();
}
});
----------------------------------------------------------------------------
appEvent
<aura:event type="APPLICATION" description="Event template" >
<aura:attribute name="message" type="Object"/>
</aura:event>
------------------------------------------------------------------------------
DisplayComp
<aura:component controller="CustomSearchController" implements="force:hasRecordId" access="global">
<aura:attribute name="disp" type="List" />
<aura:attribute name="searchText" type="String" />
<aura:handler event="c:appEvent" action="{!c.handleEvent}"/>
<aura:attribute name="accList" type="Account[]" />
<aura:attribute name="conList" type="Contact[]" />
<aura:attribute name="OppList" type="Opportunity[]" />
<c:SearchComponent /><br/>
<H1>Hello Test</H1>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div class="slds-truncate" title="Id">Id</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Name">Name</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.disp.accList}" var="dis" >
<tr>
<td scope="row" data-label=" Id" >
<div class="slds-truncate" >{#dis.Id}</div>
</td>
<td data-label="Name">
<div class="slds-truncate" >{#dis.Name}</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
----------------------------------------------------------------------------
DisplayCompController
<aura:component controller="CustomSearchController" implements="force:hasRecordId" access="global">
<aura:attribute name="disp" type="List" />
<aura:attribute name="searchText" type="String" />
<aura:handler event="c:appEvent" action="{!c.handleEvent}"/>
<aura:attribute name="accList" type="Account[]" />
<aura:attribute name="conList" type="Contact[]" />
<aura:attribute name="OppList" type="Opportunity[]" />
<c:SearchComponent /><br/>
<H1>Hello Test</H1>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div class="slds-truncate" title="Id">Id</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Name">Name</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.disp.accList}" var="dis" >
<tr>
<td scope="row" data-label=" Id" >
<div class="slds-truncate" >{#dis.Id}</div>
</td>
<td data-label="Name">
<div class="slds-truncate" >{#dis.Name}</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
I am trying to display Account, Contact & Opportunity using lightning component.
I am having 2 component one is searching and other is display. Stuck with displaying the records on the component with different tables for account,contact, and opportunity
public class CustomSearchController {
@AuraEnabled
public static getdata searchForIds(String searchText) {
getdata returndata = new getdata();
List<List<SObject>> results = [FIND :searchText IN ALL FIELDS RETURNING Account(Id,Name),Contact(Id,Name), Opportunity(Id,Name)];
Account[] accList = (Account[])results[0];
Contact[] conList = (Contact[])results[1];
Opportunity[] oppList = (Opportunity[])results[2];
returndata.acc = accList;
returndata.con = conList;
returndata.opp = oppList;
return returndata;
}
Public class getdata{
@AuraEnabled Public List<Account> acc {get;set;}
@AuraEnabled Public List<Contact> con {get;set;}
@AuraEnabled Public List<Opportunity> Opp {get;set;}
Public getdata(){}
}
}
----------------------------------------------------------------------------
SearchComponent
<aura:component implements="forceCommunity:searchInterface" >
<aura:attribute name="searchText" type="String" default=""/>
<aura:attribute name="disp" type="List"/>
<aura:registerEvent name="appEvent" type="c:appEvent"/>
<lightning:layoutItem size="3" padding="around-small">
<lightning:input value="{!v.searchText}" variant="brand" placeholder="Search" />
</lightning:layoutItem>
<lightning:layoutItem size="3" padding="around-small">
<lightning:button iconName="utility:search" variant="bare" label="Search" onclick="{! c.handleClick }" />
</lightning:layoutItem>
</aura:component>
--------------------------------------------------------------------
SearchComponentController
({
handleClick : function(component, event, helper) {
var searchbox = component.find("searchText").get("v.value");
var appEvent = $A.get("e.c:appEvent");
appEvent.setParams({"message": searchbox});
appEvent.fire();
}
});
----------------------------------------------------------------------------
appEvent
<aura:event type="APPLICATION" description="Event template" >
<aura:attribute name="message" type="Object"/>
</aura:event>
------------------------------------------------------------------------------
DisplayComp
<aura:component controller="CustomSearchController" implements="force:hasRecordId" access="global">
<aura:attribute name="disp" type="List" />
<aura:attribute name="searchText" type="String" />
<aura:handler event="c:appEvent" action="{!c.handleEvent}"/>
<aura:attribute name="accList" type="Account[]" />
<aura:attribute name="conList" type="Contact[]" />
<aura:attribute name="OppList" type="Opportunity[]" />
<c:SearchComponent /><br/>
<H1>Hello Test</H1>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div class="slds-truncate" title="Id">Id</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Name">Name</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.disp.accList}" var="dis" >
<tr>
<td scope="row" data-label=" Id" >
<div class="slds-truncate" >{#dis.Id}</div>
</td>
<td data-label="Name">
<div class="slds-truncate" >{#dis.Name}</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
----------------------------------------------------------------------------
DisplayCompController
<aura:component controller="CustomSearchController" implements="force:hasRecordId" access="global">
<aura:attribute name="disp" type="List" />
<aura:attribute name="searchText" type="String" />
<aura:handler event="c:appEvent" action="{!c.handleEvent}"/>
<aura:attribute name="accList" type="Account[]" />
<aura:attribute name="conList" type="Contact[]" />
<aura:attribute name="OppList" type="Opportunity[]" />
<c:SearchComponent /><br/>
<H1>Hello Test</H1>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div class="slds-truncate" title="Id">Id</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Name">Name</div>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.disp.accList}" var="dis" >
<tr>
<td scope="row" data-label=" Id" >
<div class="slds-truncate" >{#dis.Id}</div>
</td>
<td data-label="Name">
<div class="slds-truncate" >{#dis.Name}</div>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Do like this

Thanks for your help.This dosent work There is an error in component itself . Have you tried to Implement.