+ Start a Discussion

Can not specify 'precision' for CustomField of text Type

I am following the vb sample to create a custom field and I get the following error


null: Can not specify 'precision' for CustomField of text Type


I saw two other threads but no resolution. Precision is not being set, it shows as 0 in debug mode.


Can we get sample code to create a custom field in vb.net?


Do you have a link to the sample you're looking at. Are you using Web references or WCF ?


I am using the sample "basicSamp​le_vb_p" and running the "createCustomFieldSample"


 Private Sub createCustomFieldSample()
        'Verify that we are already authenticated, if not
        'call the login function to do so
        If Not loggedIn Then
            If Not login() Then
            End If
        End If
            Console.WriteLine(vbCrLf & "This sample will create a new Text field on the Lead object.")
            Console.Write("Enter the name that you would like for the field: ")
            Dim fieldName As String = Console.ReadLine()
            If fieldName.Length = 0 Then
                Console.Write("No name was entered for the field, so we are exiting this sample.")
            End If
            Dim cf As CustomField = New CustomField()
            cf.description = "Simple text field from API"
            cf.fullName = "Lead." & fieldName & "__c"
            Console.Write("Enter a label for the field: ")
            Dim fieldLabel As String = Console.ReadLine()
            If fieldLabel.Length = 0 Then
                fieldLabel = "Sample Field"
            End If
            cf.label = fieldLabel
            cf.length = 50
            cf.type = apexMetadata.FieldType.Text

            Dim mBinding As MetadataService = New MetadataService()
            mBinding.SessionHeaderValue = New apexMetadata.SessionHeader()
            mBinding.SessionHeaderValue.sessionId = binding.SessionHeaderValue.sessionId
            mBinding.Url = binding.Url.Replace("/u/", "/m/")

            Dim asyncResult As AsyncResult = mBinding.create(New Metadata() {cf})(0)

            Do While asyncResult.state = AsyncRequestState.InProgress

                Thread.Sleep(asyncResult.secondsToWait * 1000)
                Console.WriteLine("Checking status..." & vbCrLf & vbTab & "State:" & asyncResult.state & vbCrLf & vbTab & "Status: " & asyncResult.statusCode & vbCrLf & vbTab & "Seconds to wait: " & asyncResult.secondsToWait)
                asyncResult = mBinding.checkStatus(New String() {asyncResult.id})(0)
            If asyncResult.state = AsyncRequestState.Completed Then
                Console.Write("Custom object has been created. " & vbCrLf & vbCrLf & "Use the describe sobject sample to see your object is not listed.")
            End If

        Catch ex As Exception
            Console.WriteLine("\nFailed to create object: " & vbCrLf & ex.Message)
            Console.WriteLine("\nHit return to continue...")
        End Try
    End Sub


What version of .NET are you using ?


Visual Studio 2008 and .net framework 2.0


I just converted to .net framework 3.5 SP1 with the same result.