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
Rakesh SRakesh S 

showing error like "Component is not defined" in Lightning

Hello,

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.
Helper:

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

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


Thanks,
Rakesh
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.
 
helper.deleteAccounts(component,accountName);

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)