ABSI - far beyond system integration

On 24 February 2016     By Malinda Lamahewage      Cloud , Salesforce

Salesforce Lightning is a new UI framework to build a single application to all screen sizes with attractive UI components.

Lightning Components Framework

Salesforce Lightning Architecture

We can use Lightning App builder to build lightning apps for every screen(Responsive design) by drag and drop of Lightning Components and Visualforce pages into a one canvas.

Lightning Components are small reusable applications which are the building blocks to a lightning application and there are three types of components:

  • Standard components - built by Salesforce.com
  • Custom components - built by developers
  • Apex exchange components - built by Salesforce.com partners

In this post we are going to discuss Custom Components.

Custom components

Developers can create their own custom components. So the Administrators can create lightning apps on demand, using these components. A component is a collection of files.

Structure of a Lightning Component

Structure of a Lightning Component

Table Lightning Custom Components

Let’s create a Custom Component

1.Enable my domain in your org

For security purposes, Lightning Components require you to define a custom Salesforce domain name for your organization.

2.Upload Bootstrap as a static resource

  • Download the salesforce.com optimized Bootstrap package.
  • Unzip that package and go to Setup > Build > Develop > Static Resources and click New.
  • Specify bootstrap as the Name, then click the Choose File button, and select the bootstrap.css in the dist/css directory of the unzipped bootstrap folder.

Static resource edit

  • Click Save.

3.Create a Namespace

  • Go to Packages from setup menu.
  • Click Edit.
  • Review the selections and then click Continue.
  • Enter the namespace prefix you want to register (eg: absi_dev).
  • Click Check Availability.
  • Click Review My Selections.
  • Click Save.
  • It’s a best practice to create a Namespace.

4.Create an Apex class as the controller to write SOQL/Logic

  • Open Developer Console, click File > New > Apex Class. Name it as AccountController and click OK.

Code for AccountController class

  • Click File > Save to save the file.
  • The @AuraEnabled method annotation makes a method available to Lightning applications.

5. Creating the Lightning Application

  • In the Developer Console, click File > New > Lightning Application. Name it as MyAccounts and click Submit.
  • Click File > Save.
  • After Saving you can see this stack.

Preview

6. Creating a Component to get Data from AccountController

  • In the developer console click File > New > Lightning Component.
  • Name it as accountListComponent.
  • Click Submit.

Code for accountListComponent Component

  • To appear components in lightning pages and the App Builder, a component must implement the flexipage:availableForAllPageTypes interface.
  • In a component, use “v (view)” to access the collection of attributes.

7. Create a Controller for accountListComponent

  • Click Controller from the file list.

Accountlist Component

Code for accountListComponent’s Controller

  • doInit() function helps to load data to the component.
  • component.get("c.findAll") returns an instance of server side action.
  • action.setCallback() this function uses to set the retrieved account objects to components v.accounts attribute.
  • $A.enqueueAction() function adds the action to a queue and action calls are synchronous and run in batches.

8. Add accountListComponent to the Application UI

  • In developer console File > Open Lightning Resources.
  • MyAccounts > Application.

Code for the lightning application

  • File > Save All.
  • Click Preview or Update Preview.

Account details

Lightning Application

Conclusion

The objective of this blog is to show that how easy to create an attractive and functional component with bootstrap. The only external resource we have to use here is Bootstrap package. By using this kind of technology developers can fastly develop robust mobile and web applications on demand.