custom search not working in partner community - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Raghavi shivaramRaghavi shivaram 

custom search not working in partner community

hello,

I have a custom search replaing global search box. It is working well in the salesforce whereas , not performing any action in tha partner commuity..

1) i have apex and comity added to my profile.

Please find my code below.

customsearch.cmp

<aura:component implements="forceCommunity:availableForAllPageTypes,forceCommunity:searchInterface,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" controller="CustomSearchControllerapex">
    
    <aura:attribute name="searchText" type="String" default=""/>
      
    <div class="slds-form-element slds-lookup" data-select="single">

               <div class="slds-form-element__control">
        <div class="slds-input-has-icon slds-input-has-icon--right">
          <lightning:buttonIcon iconName="utility:search" variant="bare" onclick="{! c.handleClick }" alternativeText="Search" class="slds-input__icon" />
          <ui:inputText value="{!v.searchText}" class="slds-lookup__search-input slds-input" placeholder="Search" />
        </div>
      </div>
    </div>
 </aura:component>

customearchcontroller

({
    handleClick : function(component, event, helper) {
      var searchText = component.get('v.searchText');
      var action = component.get('c.searchForIds');
      action.setParams({searchText: searchText});
      action.setCallback(this, function(response) {
        var state = response.getState();
          
        if (state === 'SUCCESS') {
            alert('in here');
          var ids = response.getReturnValue();
          sessionStorage.setItem('customSearch--recordIds', JSON.stringify(ids));
          var navEvt = $A.get('e.force:navigateToComponent');
            navEvt.setParams({componentDef: "c:customSearchResultsList",componentAttributes :{"recordIds": ids}});
           console.log(navEvt);
            navEvt.fire();
          
        }
      });
      $A.enqueueAction(action);
    }
})

customsearchHelper

({
    SearchHelper: function(component, event) {
        // show spinner message
         component.find("Id_spinner").set("v.class" , 'slds-show');
        var action = component.get("c.fetchAccount");
        action.setParams({
            'searchKeyWord': component.get("v.searchKeyword")
        });
        action.setCallback(this, function(response) {
           // hide spinner when response coming from server 
            component.find("Id_spinner").set("v.class" , 'slds-hide');
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                
                // if storeResponse size is 0 ,display no record found message on screen.
                if (storeResponse.length == 0) {
                    component.set("v.Message", true);
                } else {
                    component.set("v.Message", false);
                }
                
                // set numberOfRecord attribute value with length of return value from server
                component.set("v.TotalNumberOfRecord", storeResponse.length);
                
                // set searchResult list with return value from server.
                component.set("v.searchResult", storeResponse); 
                
            }else if (state === "INCOMPLETE") {
                alert('Response is Incompleted');
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        alert("Error message: " + 
                                    errors[0].message);
                    }
                } else {
                    alert("Unknown error");
                }
            }
        });
        $A.enqueueAction(action);
    },
})

customsearch.css

.THIS .slds-input__icon{
   margin-top: -.8rem;
}
 
.THIS {
   padding: 0 10px;
}

customsearchdesign

<design:component label="CSP_Custom Search"> </design:component>

customsearchresuluitem.cmp

<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId,forceCommunity:searchInterface,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" 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="COMPACT"
                      targetRecord="{!v.record}"
                      targetFields="{!v.simpleRecord}"
                      targetError="{!v.recordError}"
                       />
                      

    <!-- Display a header with details about the record -->
    <div class="slds-page-header" role="banner">
      <p class="slds-text-heading--label">{!v.simpleRecord.Name}</p>
      <h1 class="slds-page-header__title slds-m-right--small  slds-truncate slds-align-left"><a href="{! $Site.siteUrlPrefix + '/' + v.simpleRecord.Id}">Go to details</a></h1>
    </div>
    <!-- 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>

customsarchresultlist.cmp

<aura:component implements="forceCommunity:availableForAllPageTypes,forceCommunity:searchInterface,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" access="global">
    <aura:attribute type="list" name="recordIds" />
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <h1>Search Results</h1>
    <aura:iteration items="{!v.recordIds}" var="id">
      <c:customSearchResultItem recordId="{!id}"/>
        
    </aura:iteration>
</aura:component>

custosearchresulylistcontroller

({
  init: function(component, event, helper) {
    var idsJson = sessionStorage.getItem('customSearch--recordIds'); 
    if (!$A.util.isUndefinedOrNull(idsJson)) {
      var ids = JSON.parse(idsJson);
      component.set('v.recordIds', ids);
      sessionStorage.removeItem('customSearch--recordIds'); 
    }
  }
})


customsearchresultcontrollerapex.apxc

public class CustomSearchControllerapex {
    @AuraEnabled
    public static List<String> searchForIds(String searchText) {
    List<List<SObject>> results = [FIND :searchText IN ALL FIELDS  RETURNING Case(Id,CaseNumber)];
    List<String> ids = new List<String>();
    for (List<SObject> sobjs : results) {
      for (SObject sobj : sobjs) {
        ids.add(sobj.Id);
      }
    }
    return ids;
}
}



kindly help me out. thanks in advance
Prashant PandeyPrashant Pandey
Hi,

Can you make sure the case is available for a partner user profile?

Also use debug and see if you are getting any value in ids for searchForIds method.