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.

Tuesday, 3 March 2020

How to Upload Google Docs in Salesforce Lightning Interface

Use Case: Do you or your team have been used to attach google docs when you are in Salesforce classic interface? How did you feel once you migrated to Lightning and figured it out that "Add Google Doc" button is missing. Sad right. This is exactly I felt when we are doing the demo to our own internal team who uses google sheets extensively and had to announce they need to switch back to classic interface to upload google docs. Who would like to do that and once they switch back to classic they stay in the same interface without switching back to classic and it reduces lightning adoption usage.

I did some research online and could not find any helpful resources like how others overcome this issue. I could just find out that the idea was posted and waiting for Salesforce to get it delivered.

Here is the idea in the success community to provide the Add Google Doc button in Lightning. Please upvote it.


Solution

Ideally my goal is to figure it out whether attaching google docs is supported in Lightning interface or not. Is Salesforce just hiding the button or the whole functionality it self is supported or not. 

I started with building a lightning component to fetch the google docs for a given record using apex controller to see if it actually retrieves data or not.

Let us first see the below apex controller. It accepts the String parameter and fetches the google docs available for the given record.


Below is the Lightning Component which uses Lightning Data Table to display the retrieved docs.

Below is the related java script controller which then calls the helper method

Below is the actual helper method which calls the apex controller method to fetch the google docs records and assign it to the gdocs attribute

At this point of time when I placed this component on the Account record page and was expecting an error message which says "Thanks for all your efforts but google docs is not supported in Lightning" , but I was shocked to see the below result. As you can see in the below screenshot I was able to get the existing docs for the record and was able to display them in the Lightning Interface. 



So it became very clear to me that it was just actually the button was missing and not the whole functionality and we can custom code it. 

So in below snippets you can find the complete code to display, add and delete the existing records in Lightning Interface with out users ever need to switch back to classic interface.

Apex Class

Apex Test Class(This can be improved but I am just providing for your reference)

Lightning Component

Lightning Component Java Script Controller

Lightning Component Java Script Helper



And a couple of screenshots to show how it looks:










  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.

P.S: This is my very first blog post, so if you see anything that can be improved in the post, please do suggest in the comments section. Thanks.