Apex Controller-What? Do we really need it?
Think of Apex Controller as a class with different methods which have been exposed over the web so that our lightning component can connect to them. These methods can fetch data from the database and send back to the component or receive some data from the component and save it into the database. All in all, a lightning component’s connection to the server-side is an Apex Controller.
Do we really need it?
Yes and No. In earlier versions/releases of Salesforce, we had to use an Apex Controller for all sorts data transactions, even for simple save and retrieve without any complex processing. People coming from Salesforce classic would be like why don’t they have a standard controller like visual force pages? Eventually Salesforce heard you and Carolyn Grabill (twitter handle @CarolynCodes) came up with Lightning Data Service! I will talk about it in detail in my upcoming posts but for now just think of it like a standard controller using which you can do most of the data retrieval and insertion for an average straight record without any processing logic. In such a scenario, you won’t be needing an Apex Controller. Sounds fun right?
So enough of blabbering and it is time to finally get to some code! Wooohoooo!! In my upcoming post I will demonstrate how Lightning Data Service (LDS) works and how a simple Apex Controller works.