Why AND How To Write Your First Salesforce Lightning Component Using Aura

Adam Parker
2 min readFeb 5, 2021

There’s a reason why being a Salesforce Developer is one of the most lucrative jobs on the market. One of those reasons are Lightning Components. Salesforce Lightning Components using Aura are great for the following reasons:

  1. You can write it right inside of developer console
  2. You are able to make use of HTML markup and CSS stylesheets for complete control over how your code looks
  3. You get to make use of the very powerful javascript language for client-side processing of your code.
  4. You can connect your front end Aura / HTML / Javascript to the backend Apex and SOQL for very powerful interactions with the Salesforce database.

To write an Aura Lightning Component you will be utilizing the MVC (Model / View / Controller) architecture.

  • Model: This would be your Salesforce database. Your lightning component can connect to your salesforce database seamlessly and allows you to access your data through your Apex controller class.
  • View: This would be your HTML markup. In your aura component you are able to include HTML, CSS, Aura tags and Lightning tags. This allows for much control over the display and view you are able to provide to your users.
  • Controller: This is very powerful because not only do you have the Apex class as your controller that can bring in the very powerful Apex programming model and connect to the Salesforce database. You also use Javascript as your controller for handling client side scripting and being a connection between your HTML and your Database.

Let me give you an example of how to get started. You will be working with 4 files.

  1. Lightning Component (TestAura.cmp)
  2. JavaScript Controller (TestAuraController.js)
  3. Apex Controller Class (TestAuraController.cls)
  4. Lightning Component App (TestAura.app) — Optional

The 4th option above is optional. This App will allow you to test or preview your lightning component without having to add your component to a lightning page. It’s not required, but very helpful when you are coding and debugging issues. When using Google Chrome when debugging you get to make use of the JavaScript console.

Here is a link to a basic custom Lightning Component built using Aura that will display a list of Accounts.

https://gist.github.com/adamparker99/6c114294f6efddbb135f64d1426539d2

Adam Parker
0 Followers

I'm Adam Parker. I am a Salesforce Technical Architect working at a major silicon valley company. I'm a dad to 8 awesome children and my wife is my best friend.

Lists

See more recommendations