Unable to find ‘getOpps’ on ‘compound://c.OpporutnityComponent’. in Lightning Component

I am new to the Lightning Experience and trying “how to use <aura:iteration> in lightning components?.”

I am following site: http://sfdcsrini.blogspot.com/2017/02/what-is-in-lightning-component-and-how.html

I am getting the below error:

This page has an error. You might just need to refresh it.
Unable to find 'getOpps' on 'compound://c.OpporutnityComponent'.
Failing descriptor: {markup://c:OpporutnityComponent}

OpportunityLightningController

public with sharing class OpporutnityLightningController {
    @AuraEnabled
    public static List<Opportunity> getOpportunities(){
        List<Opportunity> oppList = [SELECT Id, Name FROM opportunity];
        return oppList;
    }
}

OpportunityComponent.cmp

<aura:component controller="OpporutnityLightningController">
    <aura:attribute name="opplistAttr" type="Opportunity[]" />

    <ui:button label="Click Me" press="{!c.getOpps}" />
    <aura:iteration var="opt" items="{!v.opplistAttr}">
        <br/> {!opt.Name} <br/>
    </aura:iteration>
</aura:component>

OpportunityLightningAppHelper.js

({
    helperMethod : function() {

    }
})

OpportunityLightningAppController.js

({
    myAction : function(component, event, helper) {
        var oppt = component.get("c.getOpportunities");

        oopt.setCallback(this, function(response){
            var state = response.getState();
            if(state === 'SUCCESS'){
                component.set("v.opplistAttr", response.getReturnValue());
            }
        });
        $A.enqueueAction(oppt);
    }
})

EDIT-1

This page has an error. You might just need to refresh it.
Assertion Failed!: run() cannot be called on a server action. Use $A.enqueueAction() instead. : false
Failing descriptor: {ui:button$controller$press}

I am getting the new error now.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to rename either the function name in the Component controller or in the Component button press method binding, both should be same. So you can replace the myAction with getOpps.

OpportunityLightningAppController.js

({
  getOpps : function(component, event, helper) {
    var oppt = component.get("c.getOpportunities");

    oopt.setCallback(this, function(response){
        var state = response.getState();
        if(state === 'SUCCESS'){
            component.set("v.opplistAttr", response.getReturnValue());
        }
    });
    $A.enqueueAction(oppt);
  }
})

Method 2

You have a typo in the below code. It should say oppt.setCallback and not oopt.setCallback

({
  getOpps : function(component, event, helper) {
    var oppt = component.get("c.getOpportunities");

    **oopt**.setCallback(this, function(response){
        var state = response.getState();
        if(state === 'SUCCESS'){
            component.set("v.opplistAttr", response.getReturnValue());
        }
    });
    $A.enqueueAction(oppt);
  }
})


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x