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
Michael.WatkinsMichael.Watkins 

dependent picklist vb sample needed

anyone have a vb.net example for populating a dropdown list dynamically based on the controller selected value?

this seems like such a simple thing to expect from the API, but i have had no real success so far in converting the java or c# samples provided by the api documentation.

thanks in advance
ChrisGountanisChrisGountanis

THis is not optimized but does show how to populate a drop down from the Case table using the picklist "Products_Supported__c".

 

Dim dsSalesforceCaseComments As New DataTable("MyDataTable")

dsSalesforceCaseComments.Columns.Add("ProductName", System.Type.GetType("System.String"))

Dim describeSObjectResults As apex.DescribeSObjectResult() = binding.describeSObjects(New String() {"case"})

For x As Integer = 0 To describeSObjectResults.Length - 1

Dim describeSObjectResult As apex.DescribeSObjectResult = describeSObjectResults(x)

' Retrieve fields from the results

Dim fields As apex.Field() = describeSObjectResult.fields

' Get the name of the object

Dim objectName As String = describeSObjectResult.name

' Get some flags

Dim isActivateable As Boolean = describeSObjectResult.activateable

' Many other values are accessible

If fields IsNot Nothing Then

For i As Integer = 0 To fields.Length - 1

' Iterate through the fields to get properties for each field

Dim field As apex.Field = fields(i)

Dim byteLength As Integer = field.byteLength

Dim digits As Integer = field.digits

Dim label As String = field.label

Dim length As Integer = field.length

Dim name As String = field.name

Dim picklistValues As apex.PicklistEntry() = field.picklistValues

Dim precision As Integer = field.precision

Dim referenceTos As String() = field.referenceTo

Dim scale As Integer = field.scale

Dim fieldType As apex.fieldType = field.type

Dim fieldIsCreateable As Boolean = field.createable

' Determine whether there are picklist values

If picklistValues IsNot Nothing AndAlso picklistValues(0) IsNot Nothing And name = "Products_Supported__c" Then

For j As Integer = 0 To picklistValues.Length - 1

If picklistValues(j).label IsNot Nothing Then

'add row in datatable with array data matching defined columns

dsSalesforceCaseComments.Rows.Add(picklistValues(j).label)

End If

Next

Exit For

End If

' Determine whether this field refers to another object

'If referenceTos IsNot Nothing AndAlso referenceTos(0) IsNot Nothing Then

' lblViewCasesMessages.Text += "<br>Field references the following objects:<br>"

' For j As Integer = 0 To referenceTos.Length - 1

' lblViewCasesMessages.Text += "<br> " + referenceTos(j)

' Next

'End If

Next

End If

Next

dsSalesforceCaseComments.DefaultView.Sort = "ProductName"

ddlProducts.DataSource = dsSalesforceCaseComments

ddlProducts.DataBind()

Michael.WatkinsMichael.Watkins
thank you chris. however, unless i am missing something in your example, it has no provision for the dependent controller item.  what i am looking for is the dynamic population of dropdownlist2  based on the selected value of dropdownlist1.  the dependent relationships are established in the Controlling Field picklist options in setup/.  selecting a listitem in dropdownlist1 should load it's associated picklist entries into dropdownlist2


                            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
                                        If Not picklistValues(iPickListIndex).validFor Is Nothing Then
                                            oPickListEntry = New PicklistEntry
                                            For Each oPickListEntry In picklistValues

'   *******************************************************************************
'   here is the issue:
'   capture the item if its a viable picklist choice for the selected item in the controller

    if [?some vb BitSet process using the VALIDFOR objects?] then
        oDataRow = oDataSet.Tables(0).NewRow
        oDataRow.Item(0) = picklistValues(iPickListIndex).label
        oDataSet.Tables(0).Rows.Add(oDataRow)
    end if
'   *******************************************************************************
                                            Next
                                        End If
                                    End If
                                Next
                            End If



thanks again for your help!