Skip to main content

Hi All,

Please resolve the below issue. I am unable to search the values.

Component:

<aura:component controller="SearchApexClass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

    <aura:attribute name="SkillsRequired" type="String"/>

    <aura:attribute name="Salary" type="Decimal"/>

    <aura:attribute name="RelatedExperience" type="Integer"/>

    <aura:attribute name="Search" type="String" default=""/>

    <form class="slds-form--Stacked form">

        <div class="slds Search">

            <div class="Seprator"> &nbsp; </div>

            <div class="slds-grid seprate">

                <div class="slds-form-element">

                    <h1> <b>Search Options</b> </h1>

                </div>              

            </div>       

        </div>

        <div> <br/>

            <p> Skills Required </p>

            <p><ui:outputText class="result" aura:id="singleResult" value="" /></p>

            <ui:inputSelect class="single" aura:id="SkillsRequired" change="{!c.SkillChange}">

                <ui:inputSelectOption text=" "/>

                <ui:inputSelectOption text="Salesforce Admin"/>

                <ui:inputSelectOption text="Salesforce Developer"/>

                <ui:inputSelectOption text="SFDC-Integration"/>

                <ui:inputSelectOption text="SFDC-Lightning"/>

            </ui:inputSelect>

            <br/><br/>

            <p> Salary (in LPA) </p>

            <p><ui:outputText class="result" aura:id="singleResult" value="" /></p>

            <ui:inputSelect class="single" aura:id="Salary" change="{!c.CurrencyChange}">

                <ui:inputSelectOption text=" "/>

                <ui:inputSelectOption text="4"/>

                <ui:inputSelectOption text="5"/>

                <ui:inputSelectOption text="6-7"/>

                <ui:inputSelectOption text="8-10"/>

            </ui:inputSelect>

            <br/><br/>

            <p> Related Experience(In Years)</p>

            <p><ui:outputText class="result" aura:id="singleResult" value="" /></p>

            <ui:inputSelect class="single" aura:id="RelatedExp" change="{!c.ExpChange}">

                <ui:inputSelectOption text=" "/>

                <ui:inputSelectOption text="1-2"/>

                <ui:inputSelectOption text="3-4"/>

                <ui:inputSelectOption text="5-6"/>

            </ui:inputSelect>            

        </div>    <br/>

       

        <div class="slds-grid buttons">   

            <lightning:button variant="brand" label="Search" onclick="{!c.SearchButtomClick}" />

        </div>  

    </form>

</aura:component>

Controller:

({

    doInit: function(component, event, helper) {

        helper.fetchPickListVal(component, 'Industry', 'accIndustry');

    },

    SkillChange: function(component, event, helper) {

        // get the value of select option

        alert(event.getSource().get("v.value"));

    },

    CurrencyChange: function(component, event, helper) {

        // get the value of select option

        alert(event.getSource().get("v.value"));

    },

    ExpChange: function(component, event, helper) {

        // get the value of select option

        alert(event.getSource().get("v.value"));

    },

    

    SearchButtomClick: function(component, event, helper) {

        //var Search = component.get("v.search");

        var action = component.get("c.Search");

        

        action.setParams({"SkillsRequired": component.find("SkillsRequired").get("v.value"),

                          "Salary" : component.find("Salary").get("v.value"),

                          "RelatedExp" : component.find("RelatedExp").get("v.value")});

        action.setCallback(this, function(response) {

            var state = response.getState();

            if (state === 'SUCCESS') {

                var ids = response.getReturnValue();

                console.log('>>>>>' +ids);

            }

        });       

        $A.enqueueAction(action);

    }

    

})

Helper :

({

    doInit: function(component, fieldName, elementId) {

        var action = component.get("c.getselectOptions");

        action.setParams({

            "objObject": component.get("v.objInfo"),

            "fld": fieldName

        });

        var opts = [];

        action.setCallback(this, function(response) {

            if (response.getState() == "SUCCESS") {

                var allValues = response.getReturnValue();

 

                if (allValues != undefined && allValues.length > 0) {

                    opts.push({

                        class: "optionClass",

                        label: "",

                        value: ""

                    });

                }

                for (var i = 0; i < allValues.length; i++) {

                    opts.push({

                        class: "optionClass",

                        label: allValues[i],

                        value: allValues[i]

                    });

                }

                component.find(elementId).set("v.options", opts);

            }

        });

        $A.enqueueAction(action);

    },

})

Class:

public class SearchApexClass {

    @AuraEnabled

    public static List <String> getselectOptions(sObject objObject, string fld) {

        system.debug('objObject --->' + objObject);

        system.debug('fld --->' + fld);

        List <String> allOpts = new list < String > ();       

        Schema.sObjectType objType = objObject.getSObjectType();

        Schema.DescribeSObjectResult objDescribe = objType.getDescribe();

        map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();        

        list < Schema.PicklistEntry > values = fieldMap.get(fld).getDescribe().getPickListValues();             

        for (Schema.PicklistEntry a: values) {

            allOpts.add(a.getValue());

        }

        system.debug('allOpts ---->' + allOpts);

        allOpts.sort();

        return allOpts;

    }

public static string Search(String SkillsRequired, Integer Salary, String RelatedExp) {

         string returnvariable;

        list<Naukri__c> naukriList = new list<Naukri__c>();

        naukriList =  [SELECT Id,Skills_Required__c,Salary__c,Related_Experience__c FROM Naukri__c limit 10];            

        if(naukriList != null && !naukriList.isEmpty()){

            if(SkillsRequired==naukriList[0].Skills_Required__c && Salary==naukriList[0].Salary__c && RelatedExp==naukriList[0].Related_Experience__c){

                system.debug('Hiii');

                returnvariable = 'Welcome';

            }

            else{

                returnvariable = 'Please enter valid credentials';

            }

        }

        system.debug('Hiii'+ returnvariable);

        return returnvariable;   

    }

}

I am getting the error message like "This page has an error. You might just need to refresh it. Unable to find 'Search' on 'compound://c.Search'. Failing descriptor: {markup://c:Search}" while clicking on Search button.

Please look into it.

Thnaks,

Sarma
3 answers
  1. Nov 28, 2017, 1:47 PM

    Hi  Sarma Duvvuri,

    In order to use the Apex class data to Aura we need to use AuraEnabled Annotation. Try using aura enabled before your method .

     

    @AuraEnabled

    public static string Search(String SkillsRequired, Integer Salary, String RelatedExp) {

    string returnvariable;

    list<Naukri__c> naukriList = new list<Naukri__c>();

    naukriList = [SELECT Id,Skills_Required__c,Salary__c,Related_Experience__c FROM Naukri__c limit 10];

    if(naukriList != null && !naukriList.isEmpty()){

    if(SkillsRequired==naukriList[0].Skills_Required__c && Salary==naukriList[0].Salary__c && RelatedExp==naukriList[0].Related_Experience__c){

    system.debug('Hiii');

    returnvariable = 'Welcome';

    }

    else{

    returnvariable = 'Please enter valid credentials';

    }

    }

    system.debug('Hiii'+ returnvariable);

    return returnvariable;

    }

    }

     

     Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

    Regards ,

    Suraj