salesforce data migration services

Learn Salesforce Lightning with Examples – Part 4 (Select and Export records in Lightning Component)

Learn Salesforce Lightning with Examples – Part 4 (Select and Export records in Lightning Component) is the fourth part of the series – “Learn Salesforce Lightning with Examples” where We would share the key practical examples and experience with lightning.We are focusing on Lightning Components for now.

Background,Blog Contributors and Pre-Requisites

To get started for this blog you need to fulfill all the Pre-requisites mentioned here.In this link,you will also get to know the background and blog contributors for this series.

Select and Export records in Lightning Component

Business Case:

Adam is working as a Senior Application Developer in Universal Containers. Company wants to move their traditional (classic version )recruitment app to lighting. Adam needs to do a Proof of Concept by building a custom lighting component for creating the Candidate’s record into Salesforce. Now that he has created the first ,second and third part which is explained here,He would like to showcase even users know how to export a list of selected records using a simple button.

Solution:

Before getting started,Adam makes sure that he doesn’t miss any pre-requisites mentioned here.Below are the steps Adam takes for creating the solution after completing the pre-requisites.If you have followed my previous blogs,then you just need to update the components and follow these steps(Please note that if you just copy paste the complete code then you need not follow my previous blog,but I would insist you to do so if you want to learn in details)

Adam decides to go to the solution via two options :

  • First Approach is to add new button which uses a method created in lightning component.
  • Another Approach is to add a custom VF page rendered as CSV.
    • In lightning component controller action you can build the url = apex/customvf
      Use window.open(url) to open the visualforce page in new window.

Adam goes for first approach :

  1. Create 3-4 dummy records for position object for demo purpose.
  2. Update Lightning Component to export selected the list of position records.
  3. Test and host lightning component in app(ManageCandidate.app) and debug logs.

Create dummy position records

You need to set up the data to display ,so make sure you have set up some dummy data for the same.

Update Lightning Component and its controller

You have to create a lightning component which will be used to display the list of position records and select the records to perform apex action.You have to add different code for the Here is the code for lightning component,its controller and its helper:

Lightning component code

[codeblocks name=’DisplayPositionsv1.cmp’]

Lightning component controller code

[codeblocks name=’DisplayPositionsControllerv1.Js’] 

Host and test the application

You need to host the component into the application : managecandidate.app

[codeblocks name=’maangecandidate1.app’]

Now just access the app by using the URL in this format : https://{Domain Name}.lightning.force.com/c/{App Name}.app

Once you click on the button you will ask to export the report in similar way like this :

You can open this file and see that the two records exported will be here like this :

You can also download the code from the github repository here.

Hope you enjoyed the blog!If you have missed any,then you can go and check here for complete series. Stay tuned and there will be more examples to come ..