function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pedro Garcia GPedro Garcia G 

aura:component respond a custom object

Hi...

I'm creating an aura component to load a CSV file pulled from a RESTFull server.

So, I need to pass the CSV header as a List<String> and the CSV body (columns and rows) as a List<List<String>>.

So, I decided to create an internal object in the controller for this.
public with sharing class CASCsvRecordsController {

    class CSVBody{
        
        List<List<String>> csvRows {get;set;}
        
        List<String> csvHeader {get;set;}
    }
    
    @AuraEnabled
    public static CSVBody loadCSV(String csv){
        

        //The CASConnector connect with a REST server and get the CSV as String
        String fullcsvbody = CASConnector.getCSV('293880', '419356');
        
        CSVBody csvBodyObj = new CSVBody();
        
        //This is List<String> of the CSV header
        csvBodyObj.csvRows = CASCsv.getCSVRows(fullcsvbody);
        
        //This is a List<List<String>> of the line & column
        csvBodyObj.csvHeader = CASCsv.getCSVHeader(fullcsvbody);
       
        return csvBodyObj;
    }

}

I don't know and I appreciate your help to render this in the aura:component.

This is my helper
 
({
 onLoad: function(component, event) {
  console.log('onLoad call');
  
  //call apex class method
  var loadHeader = component.get('c.loadCSV');
  loadHeader.setCallback(this, function(response) {
   //store state of response
   var state = response.getState();
   if (state === "SUCCESS") {
       
    component.set('v.ListOfHeader', response.getReturnValue());

   }
      else{
          console.log("cas Failed with state: " + state);
      }
  });
  $A.enqueueAction(loadHeader);
 },
 
})

and this is a piece of my component
 
<aura:component controller="CASCsvRecordsController" >
   <!--aura init handler , call js "loadContactList" function on component load, and display contact data on table-->   
   <aura:handler name="init" value="{!this}" action="{!c.loadCsvList}"/>
    
   <aura:attribute name="ListOfHeader" type="List" />

Thanks in advance.


 

 
Ajay K DubediAjay K Dubedi
Hi Pedro,

To implement the CSV download from the server, please take help from the following link, it consists of the code to download  CSV file from the server.

http://sfdcmonkey.com/2017/04/19/download-csv-file-data-salesforce-lightning-component/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Pedro Garcia GPedro Garcia G
Thanks Ajay for your reply. I've already downloaded the CSV file... my question is: once the CSV body converts in List<List<string>>, it's pass to aura:component at var loadHeader = component.get('c.loadCSV'); How parse the List<List<string>> object in the aura:component.

The sfdcmonkey sample is good, but it doesn't cover dynamics column in the file and the case where the value could be "something, something"

I'm still working on this... so, I appreciate any help.

Thanks,
Pedro