You need to sign in to do that
Don't have an account?
ShaikA
Search page in lightning Component
Hi all,
I am creatting search page in lightning with reference to below link.
http://www.cloudforce4u.com/2016/03/salesforce-lightning-component-example.html
i am facing error like: Error during init [TypeError: Cannot read property 'apply' of undefined]
Component:
<aura:component implements="force:appHostable" controller="oppSearchController">
<aura:attribute name="opportunities" type="Opportunity[]"/>
<aura:attribute name="showtbl" type="boolean" default="false"/>
<ui:inputText aura:id="nameopp" label="Opportunity Stage" value="enter stage" required="true"/>
<ui:inputText aura:id="amntopp" label="Opportunity Amount >" value="enter amount" required="false"/>
<ui:button label="Get Opportunities" press="{!c.getOpps}"/>
<aura:if isTrue="{!v.showtbl}"> <span class="ligtn-button" style="white-space: pre;"> </span>
<table>
<thead>
<tr>
<th><strong> Name </strong></th>
<th> <strong> Stage </strong> </th>
<th> <strong> Amount </strong> </th>
</tr>
</thead>
<tbody>
<aura:iteration var="opp" items="{!v.opportunities}">
<tr>
<td><a data-record="{!opp.Id}" onclick="{!c.navigateToRecord}">{!opp.Name}</a>
</td>
<td>{!opp.StageName}</td>
<td>{!opp.Amount}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:if>
</aura:component>
Client side controller:
({
navigateToRecord : function(component, event, helper){
var navEvt = $A.get("e.force:navigateToSObject");
var selectedItem = event.currentTarget;
var Name = selectedItem.dataset.record;
navEvt.setParams({
"recordId": Name,
"slideDevName": "detail"
});
navEvt.fire();
},
getOpps: function(cmp){
cmp.set("v.showtbl","true");
var action = cmp.get("c.getOpportunities");
action.setParams({ OppStage : cmp.find("nameopp").get("v.value") , Oppamount : cmp.find("amntopp").get("v.value")}); // due this line getting above error, is there anything missing here
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.opportunities", response.getReturnValue());
}
});
<span class="lightn-buton" style="white-space: pre;"> </span> $A.enqueueAction(action);
}
})
Server side controller:
public with sharing class oppSearchController{
@AuraEnabled
public static List<Opportunity> getOpportunities(String OppStage , Integer Oppamount) {
string stageopp = '\''+OppStage+'\'';
List<Opportunity> opportunities =
[SELECT Id, Name, CloseDate,Amount,StageName FROM Opportunity where Amount >: Oppamount and StageName =: OppStage];
return opportunities;
}
}
Please help to solve this issue.
Regards,
Shaik
I am creatting search page in lightning with reference to below link.
http://www.cloudforce4u.com/2016/03/salesforce-lightning-component-example.html
i am facing error like: Error during init [TypeError: Cannot read property 'apply' of undefined]
Component:
<aura:component implements="force:appHostable" controller="oppSearchController">
<aura:attribute name="opportunities" type="Opportunity[]"/>
<aura:attribute name="showtbl" type="boolean" default="false"/>
<ui:inputText aura:id="nameopp" label="Opportunity Stage" value="enter stage" required="true"/>
<ui:inputText aura:id="amntopp" label="Opportunity Amount >" value="enter amount" required="false"/>
<ui:button label="Get Opportunities" press="{!c.getOpps}"/>
<aura:if isTrue="{!v.showtbl}"> <span class="ligtn-button" style="white-space: pre;"> </span>
<table>
<thead>
<tr>
<th><strong> Name </strong></th>
<th> <strong> Stage </strong> </th>
<th> <strong> Amount </strong> </th>
</tr>
</thead>
<tbody>
<aura:iteration var="opp" items="{!v.opportunities}">
<tr>
<td><a data-record="{!opp.Id}" onclick="{!c.navigateToRecord}">{!opp.Name}</a>
</td>
<td>{!opp.StageName}</td>
<td>{!opp.Amount}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:if>
</aura:component>
Client side controller:
({
navigateToRecord : function(component, event, helper){
var navEvt = $A.get("e.force:navigateToSObject");
var selectedItem = event.currentTarget;
var Name = selectedItem.dataset.record;
navEvt.setParams({
"recordId": Name,
"slideDevName": "detail"
});
navEvt.fire();
},
getOpps: function(cmp){
cmp.set("v.showtbl","true");
var action = cmp.get("c.getOpportunities");
action.setParams({ OppStage : cmp.find("nameopp").get("v.value") , Oppamount : cmp.find("amntopp").get("v.value")}); // due this line getting above error, is there anything missing here
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.opportunities", response.getReturnValue());
}
});
<span class="lightn-buton" style="white-space: pre;"> </span> $A.enqueueAction(action);
}
})
Server side controller:
public with sharing class oppSearchController{
@AuraEnabled
public static List<Opportunity> getOpportunities(String OppStage , Integer Oppamount) {
string stageopp = '\''+OppStage+'\'';
List<Opportunity> opportunities =
[SELECT Id, Name, CloseDate,Amount,StageName FROM Opportunity where Amount >: Oppamount and StageName =: OppStage];
return opportunities;
}
}
Please help to solve this issue.
Regards,
Shaik
try this js controller
({
navigateToRecord : function(component, event, helper){
var navEvt = $A.get("e.force:navigateToSObject");
var selectedItem = event.currentTarget;
var Name = selectedItem.dataset.record;
navEvt.setParams({
"recordId": Name,
"slideDevName": "detail"
});
navEvt.fire();
},
getOpps: function(cmp){
cmp.set("v.showtbl","true");
var action = cmp.get("c.getOpportunities");
action.setParams({ OppStage : cmp.find("nameopp").get("v.value") , Oppamount : cmp.find("amntopp").get("v.value")}); // due this line getting above error, is there anything missing here
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.opportunities", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Thanks :)
All Answers
Use the init event to initialize a component or fire an event after component construction but before rendering, like,
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
This registers an init event handler for the component. init is a predefined event sent to every component. After the component is initialized, the doInit action is called in the component's controller. In this sample, the controller action sets an attribute value, but it could do something more interesting, such as firing an event.
Setting value="{!this}" marks this as a value event. You should always use this setting for an init event.
You can call all the other actions after init has been executed.
Regards:
Alsinan
try this js controller
({
navigateToRecord : function(component, event, helper){
var navEvt = $A.get("e.force:navigateToSObject");
var selectedItem = event.currentTarget;
var Name = selectedItem.dataset.record;
navEvt.setParams({
"recordId": Name,
"slideDevName": "detail"
});
navEvt.fire();
},
getOpps: function(cmp){
cmp.set("v.showtbl","true");
var action = cmp.get("c.getOpportunities");
action.setParams({ OppStage : cmp.find("nameopp").get("v.value") , Oppamount : cmp.find("amntopp").get("v.value")}); // due this line getting above error, is there anything missing here
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.opportunities", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Thanks :)