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
OTOT 

Dynamically reference object field names VB.NET

Does anyone have an example to dynamically reference sObject fields names?

Currently, I have to explicity specify each field name. This is tedious and I don't want to do this for every object in SF.

For i As Integer = 0 To qResult.records.GetUpperBound(i)

con = CType(qResult.records(i), sforceDEV.Contact)

dsR("FirstName") = con.FirstName

dsT.Rows.Add(dsR)

Next i

What I'm trying to do is populate a dataset from constructed pick list of fields. I dynamically construct the query list so I'd like to be able to dynamically  reference each contact (con) field name when populating the dataset.

 

Thanks,

 

RJ

 

 

DevAngelDevAngel

Hi QT,

First I will pitch the sforce .NET ADO Provider.  It is on source forge at http://sourceforge.net/project/showfiles.php?group_id=96634&package_id=135890

So, if you want to do this yourself, you should pass in the SOQL statement or at a minimum the list of fields that are returned from your user.  I'd parse these into an array.  Then you can iterate the array and use reflection to get the field values from your Contact object

For j as Integer = 0 to fields.Length - 1

dsR(fields(j)) = con.GetType().GetField(fields(j), System.Reflection.BindingFlags.IgnoreCase).GetValue(con)

Next