Create a Lightning Console App

What You’ll Do

In this step, you define an initial static version of the instant notification app and deploy it as a Lightning console app.

You will:

  • Create a Lightning component for the instant notification app.

  • Deploy the component in a Lightning console app.

Follow Along with Trail Together

Want to follow along with an instructor as you work through this step? Take a look at this video, part of the Trail Together series on Trailhead Live.

(This clip starts at the 7:29 minute mark, in case you want to rewind and watch the beginning of the step again.)

Create a Lightning Component

  1. Click Setup (Setup icon) and select Developer Console.

  2. Click File > New > Lightning Component.

  3. Name the component notificationConsole.

  4. Click Submit.

  5. Change the code in notificationConsole.cmp to the following:

<aura:component implements="flexipage:availableForAllPageTypes" access="global">
  <aura:attribute name="notifications" type="List"/>
  <aura:attribute name="isMuted" type="Boolean" default="false"/>
  <aura:handler name="init" value="{!this}" action="{!c.onInit}"/>
  <aura:registerEvent name="toastEvent" type="force:showToast"/>

  <div class="container">
    <!-- Header -->
    <div class="slds-p-around_x-small slds-border_bottom slds-theme_shade">
      <div class="slds-grid slds-grid_align-spread slds-grid_vertical-align-center">
        <div>
          <span class="slds-badge">{!v.notifications.length}</span>
        </div>
        <div>
          <lightning:buttonIcon onclick="{!c.onClear}" iconName="utility:delete" title="Clear notifications"
            alternativeText="Clear notifications" variant="border-filled"/>
          <lightning:buttonIcon onclick="{!c.onToggleMute}"
            iconName="{!v.isMuted ? 'utility:volume_off' : 'utility:volume_high'}"
            title="{!v.isMuted ? 'Unmute notifications' : 'Mute notifications'}"
            alternativeText="Toggle mute" variant="border-filled"/>
        </div>
      </div>
    </div>
    <!-- Notification list -->
    <div class="slds-container_fluid slds-scrollable_y content">
      <aura:iteration items="{!v.notifications}" var="notification">
        <div class="slds-p-around_small slds-border_top">
          <div class="slds-grid slds-grid_align-spread slds-has-flexi-truncate">
            <p>{!notification.message}</p>
            <p class="slds-text-color_weak slds-p-left_x-small">{!notification.time}</p>
          </div>
        </div>
      </aura:iteration>
    </div>
  </div>
</aura:component>

Code Highlights:

  • The Lightning component contains two parts (these can be sub-components):

    • A header that contains a notification counter and buttons that enable you to clear or mute notifications.
    • A notification list that contains the messages and the time when they were sent.
  • The component uses flexipage:availableForAllPageTypes to make it available for use as a Lightning console app.

  • The component registers a force:showToast (documentation) standard Lightning event that we use to display toast notifications in Lightning Experience.

  1. Save the file either by clicking File > Save menu or by pressing Ctrl + S.

Add a Controller to the Component

  1. Create a controller for the notificationConsole component by clicking Controller on the right-hand side of the Developer Console.

  2. Replace all of the default code with the following:

({
  onInit: function (component, event, helper) {
    component.set('v.notifications', [
      { time: '00:01', message: 'Greetings Trailblazer!' },
      { time: '00:02', message: 'Congratulations on building this first version of the app.' },
      { time: '00:03', message: 'Beware of the bears.' }
    ]);
    helper.displayToast(component, 'success', 'Ready to receive notifications.');
  },

  onClear: function (component, event, helper) {
    component.set('v.notifications', []);
  },

  onToggleMute: function (component, event, helper) {
    const isMuted = component.get('v.isMuted');
    component.set('v.isMuted', !isMuted);
    helper.displayToast(component, 'success', 'Notifications ' + ((!isMuted) ? 'muted' : 'unmuted') + '.');
  }
})

Code Highlights:

The controller provides three controller functions:

  • onInit initializes the component data with three hard-coded notifications and displays a toast that indicates that the app is initialized.

  • onClear clears the notification history.

  • onToggleMute toggles between the muted and unmuted state (whether notifications are displayed in toasts).

  1. Save the file.

Add a Helper to the Component

  1. Create a helper for the notificationConsole component by clicking Helper on the right-hand side of the Developer Console.

  2. Replace all of the default code with the following:

({
  displayToast: function (component, type, message) {
    const toastEvent = $A.get('e.force:showToast');
    toastEvent.setParams({
      type: type,
      message: message
    });
    toastEvent.fire();
  }
})

Code Highlights:

The displayToast function fires the standard showToast Lightning application event. This displays a toast in the Lightning Experience.

  1. Save the file.

Style the Component

  1. Create a style sheet for the notificationConsole component by clicking Style on the right-hand side of the Developer Console.

  2. Replace all of the default code with the following:

.THIS.container {
  height:100%;
}
.THIS .content {
  height:calc(100% - 49px);
}

Code Highlights:

We set special style rules for the container and list content to maximize their height.

  1. Save the file and close the Developer Console.

Deploy a Lightning Console App

  1. From Setup, enter App Manager in the Quick Find box, then select App Manager.

  2. Locate the Sales application that is Lightning-enabled. (Look for a check mark in the Visible in Lightning column next to Lightning in the App Type column). Click the down arrow on the right-hand side and select Edit.

  3. Navigate to Utility Items.

  4. Click Add Utility Item next to Utility Items.

  5. Scroll down the list of components and select notificationConsole under Custom.

  6. Set the following properties for the component:

    • Label: Notifications
    • Icon: announcement
    • Panel Width: 340 (default value)
    • Panel Height: 300
    • Check the box next to Start automatically.

Utility bar configuration screen

  1. Click Save, then click Back Back button.

From the App Launcher (App launcher icon), find and select Sales. You can now see a "Ready to receive notifications" toast displayed, and the Notifications Lightning console app at the bottom of the screen. Click the Notifications app, and it expands with the three notifications we hard coded as illustrated below.

An Image showing the "Ready to Receive notifications" toast and the Notifications Lightning console app with the three hard-coded notifications.

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities