I’m not embarrassed to admit that I avoided learning about Lightning and building lightning components for quite a long time. To illustrate the intensity of my disdain for Lightning, despite Salesforce’s persistent tries to change my orgs to lightning experience (LE), I constantly changed back to “Classic.” I still have moments where I use classic, because frankly when doing administration tasks, it can be very annoying to see a classic page iframed into LE. Plus annoying things happen like in certain contexts, when you press “Save & New” instead of “Save” (and then “New”), the page header loads but the rest never appears, and you have to refresh! C’mon, Salesforce.
Okay, rant over. Adapt or die, right? I bit the bullet and learned, mostly because I was required to do so by a project.
Lightning is still very new to me and the documentation is occasionally lacking — what I mean is, it’s easy to find documentation of the various bits and pieces, but finding examples that pull everything together in a way that’s relevant and based on a real-world scenario? Not so easy. Hopefully this can begin to fill that gap.
We will build upon this component in further tutorials — so this is an important place to start.
To give a realistic example, let’s create a lightning component that lists recently used Accounts. We could use it in various places in our Salesforce org, as part of lightning applications or on the home page, for example.
I like to start from the backend and move to the frontend. We will create three pieces, in the following order:
- An Apex Controller
- A Lightning Component
I’m going to break this into pages so it’s easier to follow. Let’s get started by navigating to the next page, where we’ll build the Apex Controller which retrieves our data.