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
ChrisGountanisChrisGountanis 

Getting Picklist Data for .NET Combobox

How do you run an API call to get picklist data to fill a dropdown in .NET VB would be the easiest for me. What I am trying to do is get a list of case origins which is a picklist object to fill a drop down in my external API based application. I am reading, creating new and updating records but for some reason this is not easy for me to figure out.
Michael.WatkinsMichael.Watkins
here is an example that may help-

'aspx.vb code behind
...
            '   populate type
            Dim oCase As New sfCase
            lstType.DataTextField = "ID"
            lstType.DataValueField = "PickListValue"
            lstType.DataSource = oCase.GetCaseType
            lstType.DataBind()

            oListItem = New ListItem
            oListItem.Text = "--none--"
            oListItem.Value = ""
            lstType.Items.Insert(0, oListItem)


        Public Function GetCaseType() As DataSet
            Dim oSelfServiceUser As SelfServiceUser = System.Web.HttpContext.Current.Session("SalesForceSelfServiceUserData")
            Dim oProxy As SforceService = sfUtilities.GetProxy()
            Dim oDataSet As New DataSet
            Dim oCase As New sfCase

            Dim oResults As sforce.DescribeSObjectResult()
            oResults = oProxy.describeSObjects(New String() {"Case"})


            Dim oTable As New System.Data.DataTable

            oTable.Columns.Add("ID")
            oTable.Columns.Add("PickListValue")
            oDataSet.Tables.Add(oTable)

            For iIndex As Integer = 0 To oResults.Length - 1
                Dim describeSObjectResult As sforce.DescribeSObjectResult = oResults(iIndex)
                Dim oFields As sforce.Field() = describeSObjectResult.fields
                If Not oFields Is Nothing Then
                    For iFieldIndex As Integer = 0 To oFields.Length - 1
                        Dim oField As sforce.Field = oFields(iFieldIndex)
                        Dim oName As String = oField.name
                        Dim picklistValues As sforce.PicklistEntry() = oField.picklistValues
                        Dim fieldType As sforce.fieldType = oField.type

                        If LCase(oName) = "type" Then
                            If (Not picklistValues Is Nothing AndAlso Not picklistValues(0) Is Nothing) Then
                                For iPickListIndex As Integer = 0 To picklistValues.Length - 1
                                    If Not picklistValues(iPickListIndex).label Is Nothing Then
                                        Dim oDataRow As DataRow = oDataSet.Tables(0).NewRow
                                        oDataRow.Item(0) = picklistValues(iPickListIndex).label
                                        oDataRow.Item(1) = picklistValues(iPickListIndex).label
                                        oDataSet.Tables(0).Rows.Add(oDataRow)
                                    End If
                                Next
                            End If
                        End If


                    Next
                End If
            Next

            Return oDataSet

        End Function

ChrisGountanisChrisGountanis
It does using DescribeSObjectResult is working for me. I was hoping for a direct hit like a simple 2-4 liner to get results into a drop down. This wild looping works for now and seems to be fast enough.