function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ramayya dasamramayya dasam 

Unable to find action 'createAccount' on the controller of c:Event11comp

Hi all ,
     I had also faced the similar issue  (Unable to find action 'createAccount' on the controller of c:Event11comp ).    please go through the code below 
Event :
         <aura:event type="APPLICATION" description="Event template" >
         <aura:attribute name="acc" type="Account"/>
        </aura:event>

component 1 :
  <aura:component >
    <aura:registerEvent name="first" type="c:Event11"/>
    <aura:attribute name="acc" type="Account" default="{'sobjectType':'Account'}" />
    <div style="margin-left:100px;margin-top:100px;width:500px;border:1px solid green;">
        <lightning:card title="" iconName="standard:account">
            <aura:set attribute="title">
                <h1>New customer</h1>
            
            </aura:set>
            <aura:set attribute="actions">
                <lightning:button label="save" onclick="{!c.doSave}"/>
                <lightning:button label="cancel" onclick="{!c.doCcancel}"/>
             </aura:set>
                 <div style="padding:20px;">
                     <lightning:input label="Name"     value="{!v.acc.Name}"/>
                     <lightning:input label="Phone"    value="{!v.acc.Phone}"/>
                     <lightning:input label="Industry" value="{!v.acc.Industry}"/>                  
                </div>
    
    
    
    
        </lightning:card>
    </div>
    
</aura:component>

component 1 controller :
              ({
    doSave : function(component, event, helper) {
        var accRecord = component.get("v.acc");
        var action = component.get("c.createAccount");
        action.setParams({"objA":accRecord});
        action.setCallback(this,function(response){
            var state = response.getState();
            if(state == 'SUCCESS'){
                var res = response.getReturnValue();
                if(res !='Error'){
                var evt = $A.get("e.c:Event11");
                evt.setParams({"acc":accRecord});   
                evt.fire();
            }
            }
        });
        
        
        
        
        
        
        
        $A.enqueueAction(action);
        
    },
    doCancel : function(component, event, helper) {
        component.set("v.acc",null);
    }
})


component 2 :
       <aura:component controller="controllerDml">
    <aura:attribute name="accountdata" type="Account" default="{'sobjectType':'Account'}"/>
    <aura:attribute name="flag" type="boolean"  default="flase"/>
    <aura:handler name="Submit" event="c:Event11" action="{!c.doSubmit}"/>
   
    <aura:if isTrue="{!v.flag}">
     <div style="margin-left:100px;margin-top:100px;width:500px;border:1px solid green;">
       <lightning:card title="customer Details" iconName="standard:account">
           <div style="padding:20px;"> 
            <b>Name</b>     :  {!v.accountdata.Name}<br/>
            <b>Phone</b>    :  {!v.accountdata.Phone}<br/>
            <b>Industry</b> :  {!v.accountdata.Industry}
           </div>
       </lightning:card>
     </div>
    
    
    </aura:if>
    
</aura:component>
component 2 controller:

({
    doSubmit : function(component, event, helper) {
        var acc1 = event.getParam("acc");
        component.set("v.accountdata",acc1);
        component.set("v.flag",true);
        
    }
})

Application:
 <aura:application extends="force:slds" >
    <c:Event11comp />
    <c:Event11comp1 />
    
</aura:application>

Apex class:

 public class controllerDml {
    @auraEnabled
    public static string createAccount(Account objA) {
         try{
             Insert objA;
             return objA.Id;
            }
          catch(Exception e) {
              return 'Error';
               }
    }

}
 
Best Answer chosen by ramayya dasam
Sachin HoodaSachin Hooda
Hi Ramaya,
It's because you forgot to add Controller on your Component 1. Since you're using a method without implementing the controller, the component is unable to find any method called "createAccount".
So, Please make changes like
<aura:component controller="controllerDml" access="global">
      <!-- your code here-->
</aura:component>
That would be it.
_____
Regards,
Sachin
(:

All Answers

Sachin HoodaSachin Hooda
Hi Ramaya,
It's because you forgot to add Controller on your Component 1. Since you're using a method without implementing the controller, the component is unable to find any method called "createAccount".
So, Please make changes like
<aura:component controller="controllerDml" access="global">
      <!-- your code here-->
</aura:component>
That would be it.
_____
Regards,
Sachin
(:
This was selected as the best answer
ramayya dasamramayya dasam
Hi Sachin,
  Firstly thanks for the reply ,as u said i am adding this <aura:component controller="controllerDml">  . once click on" save" button it's not opening the  component 2 page .please, check the output once again.
Regards,
 Ramayya.
Sachin HoodaSachin Hooda
Hi Ramaya,
Is there any error or the event is not getting fired?
Please try placing some debug logs.
______
Regards, 
Sachin
(:
ramayya dasamramayya dasam
Hi Sachin,
 User-added image
This is the ouput attacthed above  .

Regards,
 Ramayya.
 
Sachin HoodaSachin Hooda
Hi Ramaya,
Please try placing a debug log for the callback state.
And please make some changes as,
if(res !='Error'){
                var evt = $A.get("e.c:Event11");
                evt.setParams({"acc":accRecord});   
                evt.fire();
            }

to
if(res !="ERROR"){
                var evt = $A.get("e.c:Event11");
                evt.setParams({"acc":accRecord});   
                evt.fire();
            }


​​​​​​In case, you still have any problem, please post them here.
_________
Regards,
Sachin
(:

ramayya dasamramayya dasam
Hi Sachin,
   As u said i am placing debug log also.  Still  I 'am getting the same issue.please check the code
Regards,
 Ramayya.
ramayya dasamramayya dasam
Hi Sachin,



                                    User-added image

  As u said i am placing debug log at                 
                                                             var evt = $A.get("e.c:Event11");
                                                              alert("error check :"+ evt);
                                                             evt.setParams({"acc":accRecord});   
                                                              evt.fire();
I am getting this msg above .please tell me what can i do 
Regards,
Ramayya.
 
Sachin HoodaSachin Hooda
Hi Ramayya,
Please make the following changes & let me know if the problem still persists.
1. Please change,
if(res !='Error'){
                var evt = $A.get("e.c:Event11");
                evt.setParams({"acc":accRecord});   
                evt.fire();
            }
to
if(res !="ERROR"){
                var evt =component.getEvent("first");
                evt.setParams({"acc":accRecord});   
                evt.fire();
            }
in the register component.
2.  On the component where the event has to be handled,
var accRecord = event.getParam("acc");
component.set('v.accRecord',accRecord);
And place debug logs to confirm the event is called & account record is passed.
If you still have any doubt feel free to ask.
_______
Regards,
Sachin
(:
ramayya dasamramayya dasam
Hi Sachin,
 User-added image

User-added image
 As u said I am placing  still  I 'am getting the same issue.please check the code once,thank u
Regards ,
Ramayya.
ramayya dasamramayya dasam
Hi Sachin,


                     User-added image

What was the meaning of this error message . please explain 
                                   thank u,

Regards,
Ramayya.

 
Sachin HoodaSachin Hooda
Hi Ramaya,
This isn't an error. This is an object populated while the component gets metadata of the event.
Remove this alert & place debug logs in 2nd component to check whether the event is fired & data has been passed to the second component.
And if data is being passed. Please proceed further with the UI part.

_________
Regards,
Sachin
(: