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 

custom data type

Hi...

I have an CSV file wich the amount and type of column (field) could be changable. The first row has the column (field) name.

I already pull the CSV into SF.

Now, I need to render it in a Lightning page and manipulate it (sort by, search, etc)

My thoughs:
Using a controller to put all CSV records in a List and render it in the page.
My PROBLEM, what data type could I assign to the list?

Could I build dynamically a data type when I read the first line of the CSV file?

List<CustomTypeData> mylist = new
List<CustomTypeData> ();

Thanks
 
Navin Selvaraj23Navin Selvaraj23
Hi Pedro,

Could you please let me know why you are going to apex controller?  you can read and manipulate in JavaScript itself. Sorting can also be done in Javascript. Searching also could be doable. If you want to perform search operation in apex controller, you can go with String data type.

Regards,
Navin S
Pedro Garcia GPedro Garcia G
Hi Navin,

The CSV has information of Account, Contact, Opportunities and others custom object. The SF user (student service office) want to see what applicants have been already in the SF and who is new. They will decide which will be imported or not.

So, my question only include a small part of the whole requirements.

I want to avoid (if it's possible) write in hard code all possible combination of columns in the CSV.

Thanks,
Pedro
Navin Selvaraj23Navin Selvaraj23

Yeah Pedro,

you can do  without hard coding. 
For example I will take and explain with account:

You should be having one uniqueue column in each object where the record you are going to insert or update. pull off the unique column in the list and query using that list.

Then compare csv details and SF data returned from that query. Then frame a wrapper class. Then return that to client side. you can display.
The wrapper will be like,

public class ObjectWrapper{
public boolean isNewRecord;
public sObject record;
}
while framing wrapper, you can set false to isNewRecord for the records that are aleady availabe in salesforce. and set the particular record to sObject record. you can frame a list of wrapper and return.

Approach 2:
In CSV itslef, if you are going to update any record, Id will be present. else you cannot update the record. For new records, no id will be present. you can use that to seperate new records and already availabel records.

Please have a look and let me know if this is useful. else you share me the sample csv. Then we will dicsuss.

Regards,
Navin S

Pedro Garcia GPedro Garcia G

Thank Navin... I'll try your point and let you know.. Yes, the CSV is comming with a field that never change. It's my External ID for Contact... As I'm using HEDA, the Account always is associated with Contact with specific record type.

Is there a way to create dynamically the properties of the ObjectWrapper class based on first row of the CSV?

Thanks,

Navin Selvaraj23Navin Selvaraj23
Why you need first row to create the object wrapper class. obviously first row is going to be heading(column names) of the record/table.
you sould not specify any sobject name such as Account or contact in wrapper, just declare sobjectype and related fields in generic manner where you can use that wrapper class to all the objects.

Example wrapper as below for your reference:
public class OuterClass{

public class WrapperClass{
    public string isNewRecord{get;set;}
    public sObject sObjectRec {get;set;} // sobject - Generic Object
    public WrapperClass(String isNewRecord, sObject sObjectRecord) {
        isNewRecord = isNewRecord;
        sObjectRec = sObjectRecord;
    }
}

I think you are looking for this.else please comment below with little more detail


Regards,
Navin S
Pedro Garcia GPedro Garcia G
Thanks Navin... I see you point... I'll try it and let you know...