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
dptr1988dptr1988 

How can I create lists of fields?

 I want to give the user a list of fields from the 'Contacts' object and have them select the fields that they want to use. Then I want to store that list of fields and retrieve it latter to know which fields to access.
 
 The goal of this program is to allow users to export a contact with one button click. So rather then having them select the fields that they want to export each time, I am wanting to store a pre-selected list of fields and then just exports those fields of the contact that they selected. If they have any custom fields in the 'Contacts' object, I would like to be able to handle those fields too.

In PHP/MySQL, you could just DESCRIBE the table, have the user select the list of field names and then when you go to run the export query, you would just insert the selected field names in the SELECT statement like "SELECT {$field_list} FROM table WHERE id = {$id}".

 After reading the apex manual, the only way that I could find to do this was through 'Dynamic DML' or 'Dynamic SOQL', which according to the manual, is a 'pilot program' and should not be used for regular production. Apparently, apex has just implemented and is testing a 'new' feature that has been around in other programming languages for years? Is there any other way to do this?
 
 Also, does apex have any data type of 'pointers' or 'references' to other variables? I was not able to find a way of making var_1 refer to var_2 so that modifying var_1 would result in var_2 be modified also. The best I could find for pointers was the 'List or Set Iteration For Loops' ( like "for (Integer i : myInts) { /* do something */ }" ). But it almost sounds like they are just assigning the variable 'i' a value from the 'myInts' list rather then making it refer to it. So, it looks like its a 'read-only' reference. Is there any way of doing this?

Peter