You need to sign in to do that
Don't have an account?
Akhil Katkam 5
why apex is not calling from controller method in developer console
Hi Developer Community,
I was not able to find why my apex is not calling from controller method ,
can anyone please tell me the reason for this.
please check my code below
request1 : function(component, event, helper) {
var recId = component.get("v.selectedId");
alert('hi');
// var recordId =component.get("v.recordId");
var action = component.get("c.fetchCompetitions");
action.setParams({
"recordId" : component.get("v.recordId"),
"recId" : recId
});
$A.enqueueAction(action);
}
APEX code:
@AuraEnabled
public static void fetchCompetitions(String recordId, String recId){
System.debug('hi');
system.debug('recordId' +recordId);
system.debug('recId' +recId);
List<Opportunity> opp=new List<Opportunity>();
Opportunity o = [select id,Name,MainCompetitors__c from Opportunity where id=:recordId];
List<Competitor__c> cmptList=[select id,Name from Competitor__c where id=:recId];
for(Competitor__c comp : cmptList){
Opportunity opList = new Opportunity();
opList.MainCompetitors__c = comp.Name;
opp.add(opList);
}
update opp;
system.debug('opp' +opp);
}
I was not able to find why my apex is not calling from controller method ,
can anyone please tell me the reason for this.
please check my code below
request1 : function(component, event, helper) {
var recId = component.get("v.selectedId");
alert('hi');
// var recordId =component.get("v.recordId");
var action = component.get("c.fetchCompetitions");
action.setParams({
"recordId" : component.get("v.recordId"),
"recId" : recId
});
$A.enqueueAction(action);
}
APEX code:
@AuraEnabled
public static void fetchCompetitions(String recordId, String recId){
System.debug('hi');
system.debug('recordId' +recordId);
system.debug('recId' +recId);
List<Opportunity> opp=new List<Opportunity>();
Opportunity o = [select id,Name,MainCompetitors__c from Opportunity where id=:recordId];
List<Competitor__c> cmptList=[select id,Name from Competitor__c where id=:recId];
for(Competitor__c comp : cmptList){
Opportunity opList = new Opportunity();
opList.MainCompetitors__c = comp.Name;
opp.add(opList);
}
update opp;
system.debug('opp' +opp);
}
Please try to use code like below:
Apex code can be kept as is.Also ensure you are using controller="ApexClassName" in your component definition file.
Refer this documentation for more help:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.
All Answers
Have you add Controller attribute in <aura:Component tag to link the Apex Class like <aura:component controller="CLASSNAME">?
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
Please try to use code like below:
Apex code can be kept as is.Also ensure you are using controller="ApexClassName" in your component definition file.
Refer this documentation for more help:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.
You need to use below line in your component
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh