Apex Controller-What? Do we really need it?

by | Aug 22, 2018 | Lightning | 0 comments

So in my previous post, I explained about the different sub-components that make the lightning component. All of them were client-side components. But what if you need to get something from the server? Like pulling data from a server? or saving data back to the server? A component with static content isn’t gonna do you much good. So in essence, we need something which would let our lightning component talk to the server. Enter Apex Controller!

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.

 

Bishwambhar Sen
Bishwambhar Sen is an IT professional with over 10 years of industry experience. He is a Salesforce certified developer and admin. When he is not configuring and customising, he loves photography, traveling and blogging.
Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This