I am trying to call an apex method through a controller. I have read somewhere the apex methods without any return should be prefixed with get. I am not sure what I am doing wrong here. It says cant find the method. here is the apex:

        for (Opportunity opp : [Select Id, Name, StageName from Opportunity]) {
        opp.StageName = 'Won';
        update opp;

Here is the call from the controller:

changeStageBackWon : function(component, event, helper) {
    var updateOpportunityStageBackWon = component.get("c.getMoveOppBackWon");
    //updateOpportunityStageBackWon.setParams({ opps : component.get("v.opportunityData") });
    updateOpportunityStageBackWon.setCallback(this, function(response) {
        var state = response.getState();            
        if (state === "SUCCESS") {
            var result = response.getReturnValue();
  • 1
    How is your method declared in Apex? – Jayant Das Dec 21 '18 at 21:23
  • I have read somewhere the apex methods without any return should be prefixed with get. This generalization makes no sense. – Adrian Larson Dec 21 '18 at 22:52
  • Hey Adrian, this was the msg that I got from dev console "non static auraenabled methods must be named with a prefix 'get'" when i ran my code initially. At that time i didn't have static included in my declaration. – sumchans Dec 21 '18 at 22:56

In all Apex methods, that are not returning something back, we will need to declare them as void. So you need to do something like this:

public static void theVoidMethod(){

// Your code here 



public void theVoidMethod2(){

    // Your code here 


Check this link to learn more about Apex methods.

  • Thanks Carlos, I was doing the same, for some reason it was not working then, but now its working. I do the coding on developer console, once you save , it takes a while to see that reflected on the browser. Not sure as of now how to fix that. – sumchans Dec 21 '18 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.