Sunday 26 April 2020

How to Download Data From Parent & Child Objects as a CSV File in Lightning using Aura Components

Use Case: Todays post is about how to download/export data from your lightning(Aura) component as a CSV file. This is the most common expectation these days by business users where they want to download the data present in tabular format so that they can use it for further analysis. There are couple of other blogs where you can find the code for this scenario but their logic do not support when you pull data from child and parent objects in single query. So I have spent some time refactoring some of the code available and based on user comments to address those missing parts. 

Below is the Lightning Component which displays list of opportunities along with download button


Javascript controller


Javascript helper which holds the logic of formatting the data to make it compatible to download parent and child records without any issues



And a couple of screenshots to show how it looks:



Hit the Download As CSV button will download the data and when it is opened you can see data in below format:


If this post really helped you to fix your issue please let me know in the comments section. Also please share it with your friends who can benefit from similar situation.

No comments:

Post a Comment