Retrieve Records in Lightning

By | August 20, 2016

Lightning is described as the future of the Salesforce. Lightning uses JavaScript on client side and apex on the sever side and this is one of the prominent reason why Lightning has faster execution rate. If you haven’t enabled lightning in your Salesforce org yet, here’s a blog that can help you do so Enable Lightning Experience on Salesforce.

You can create new apps, controller, components from the Developer Console and preview them through Developer Console. We will discuss how to read records from Salesforce and we will soon come up with another blog that will talk on saving records to Salesforce in Lightning.

To read records from Salesforce, we will first create an Apex class that will fetch all respective records. The function in the class has to be annotated with ‘@AuraEnabled’ this enables the Lightning components to communicate with Salesforce. Refer the below image regarding the apex class. Refer the below image regarding the apex class.

Apex controller

Apex controller

Through developer console, create a new Lightning component that will use the controller, you just created, and will consist of markup to display the records. Refer the below image for Lightning component

Lightning Component

Lightning Component

Now, we have the two pieces ready for and we need the third piece that will join them together and this is done via JavaScript controller. This calls the apex controller and binds the Lightning component with the results returned from the Apex Controller. Refer the below image for the controller

Lightning Component Controller for reading records

Lightning Component Controller for reading records

You can apply style/CSS to make your component look more appealing. Once, you are done just refer the Lightning component in your lightning app the same way you use VisualForce component in your VisualForce page. You can then preview the App and see the output. Refer the image below for Lightning app and the desired outcome.

Lightning App to display records

Lightning App to display records

Output Displaying All records retrieved

Output Displaying All records retrieved

About Us
Greytrix as a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners across the globe. We offers Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that requires apex code incorporation into the Salesforce platform.

Greytrix has some unique solutions for Cloud CRM such as Salesforce integration with Sage Enterprise Management (Sage X3), Sage Intacct, Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data Migration, Integrated App development, Custom App development and Technical Support to business partners and end users.

Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star app listed on Salesforce AppExchange.

For more information, please contact us at salesforce@greytrix.com. We will be glad to assist you.

Related Posts