+ Start a Discussion
Rakesh SRakesh S 

showing error like "Component is not defined" in Lightning


I'm trying to delete an account whenever clicking on the delete button(lightning button). I'm passing the selected account name to Helper where i want to call apex method by passing the parameter.

    	deleteAccounts: function(accountName){
            console.log('accountName: ',accountName);// getting name here- Test Account
            var action = component.get('c.deleteAccounts');
                 "accName": accountName        

the follwing error getting while doing the delete operation.
User-added image
Please help me to define component.

Khan AnasKhan Anas (Salesforce Developers) 
Hi Rakesh,

Greetings to you!

Firstly, you need to call the helper method from the controller that deals with the rest of the code with proper parameters.

Then in helper create the function and use the parameters from the controller to construct your function.
deleteAccounts: function(component,accountName) {
     //Your code

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Aditya VijayvargiyaAditya Vijayvargiya
In line 7, you are using component.get(), and component is not passed from controller, so while calling the helper.deleteAccounts from controller, you need to write 
helper.deleteAccounts(component, accountName)

and change the declaration of helper method as 
deleteAccounts: function(component, accountName)