You need to sign in to do that
Don't have an account?
Dhiraj Gupta 1
not able to call apex method from controller JS
Hi Team,
I am calling apex class from constrctor but while debugging i am getting below error and cursor is not going inside setCallback method. It seems it is not calling apex class. Below is code:
Error is:
his page has an error. You might just need to refresh it. Action failed: c:BeerExplorer$controller$handleCompEvents [Invalid key search] Failing descriptor: {c:BeerExplorer$controller$handleCompEvents}
Controller code:
({
handleCompEvents : function(component, event, helper) {
var searchParam=event.getParam('searchText');
var action=component.get('search');
action.setParams({
txtSearch:searchParam
});
action.setCallback(this,function(response){
var state=response.getState();
if(state=='SUCCESS')
{
var responseValue=response.getReturnValue();
console.log('responseValue',responseValue);
}
})
}
})
Apex Class:
public class BeerExplorer {
@AuraEnabled
public static List<Beer__c> search(string txtSearch)
{
string likeParam='%' + txtSearch + '%';
string query= 'select Id, Name, From Beer__c where Name Like: likeParam ';
List<Beer__c> beerList=Database.query(query);
return beerList;
}
}
I am calling apex class from constrctor but while debugging i am getting below error and cursor is not going inside setCallback method. It seems it is not calling apex class. Below is code:
Error is:
his page has an error. You might just need to refresh it. Action failed: c:BeerExplorer$controller$handleCompEvents [Invalid key search] Failing descriptor: {c:BeerExplorer$controller$handleCompEvents}
Controller code:
({
handleCompEvents : function(component, event, helper) {
var searchParam=event.getParam('searchText');
var action=component.get('search');
action.setParams({
txtSearch:searchParam
});
action.setCallback(this,function(response){
var state=response.getState();
if(state=='SUCCESS')
{
var responseValue=response.getReturnValue();
console.log('responseValue',responseValue);
}
})
}
})
Apex Class:
public class BeerExplorer {
@AuraEnabled
public static List<Beer__c> search(string txtSearch)
{
string likeParam='%' + txtSearch + '%';
string query= 'select Id, Name, From Beer__c where Name Like: likeParam ';
List<Beer__c> beerList=Database.query(query);
return beerList;
}
}
Use a console.log(action); to see if you are getting that right.
If it helps please mark as correct, it may help others.
It worked at this point but it is not able to call apex class. Getting below error:
HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
I assume the code is incomplete and you enqueue the action to be executed, if not please do so.
$A.enqueueAction(action);
If it helps please mark as correct.
I can see below for conole.log(action). Under which i can see c.search method?
getCallback: ƒ ()
getError: ƒ ()
getName: ƒ ()
getParam: ƒ ()
getParams: ƒ ()
getReturnValue: ƒ ()
getState: ƒ ()
isBackground: ƒ ()
setAbortable: ƒ ()
setBackground: ƒ ()
setCallback: ƒ ()
setParam: ƒ ()
setParams: ƒ ()
setStorable: ƒ ()
toString: ƒ ()
Also under setParams i should be able to see property txtSearch but it is not available.
Check with console.log(searchParam);
If you are not getting a String then that might be the error when passing the parameter.
Try debugging that and also put a system.debug(txtSearch) on the apex method to see what you get.
Hi,
While calling Apex class, getting response state INCOMPLETE with error net::ERR_CONNECTION_RESET. How to fix this error?