You need to sign in to do that
Don't have an account?
sforceofficetoolkit and ampersand (&)
I have a VB 6 application (not .NET) which writes data sfdc using the sforce Office Toolkit DLL. The program hangs when I attempt to insert or update a record where the first character in a field is an ampersand (&. I was able to duplicate the issue in the Excel connector, so I'm pretty sure this is an issue with the toolkit DLL. It does not happen if the ampersand is any other position besides the first one.
Is there an escape character I can use, or a routine I can call, to properly encode this character so it doesn't hang up my program?
Here is an example of code that causes the program to hang:
-------------------------------------------------------
Note: VB 6 app has a reference to the sforceofficetoolkit v2.0, and a form with 3 command buttons (cmdOK, cmdSearch, cmdUpdate) and 8 textboxes (txtUserName, txtPassword, txtQueryName, txtName, txtBillingStreet, txtBillingCity, txtBillingState, txtBillingPostalCode).
The following is the code for the form:
Option Explicit
Dim oSFDC As New SForceOfficeToolkitLib.SForceSession
Dim qs As SForceOfficeToolkitLib.QueryResultSet
Dim oItem As SForceOfficeToolkitLib.SObject
Dim sSQL As String
Private Sub cmdOK_Click()
If oSFDC.Login(Me.txtUserName.Text, Me.txtPassword.Text, False) Then
MsgBox "Login successful"
Else
MsgBox "Login failed"
End If
End Sub
Private Sub cmdSearch_Click()
oSFDC.Login Me.txtUserName.Text, Me.txtPassword.Text, False
sSQL = "Select Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode from Account where name = '" & Me.txtQueryName.Text & "'"
Set qs = oSFDC.Query(sSQL, False)
If qs.Size = 0 Then
MsgBox "No data found for search criteria."
End If
For Each oItem In qs
Me.txtName.Text = oItem("Name").Value
Me.txtBillingStreet.Text = oItem("BillingStreet").Value
Me.txtBillingCity.Text = oItem("BillingCity").Value
Me.txtBillingState.Text = oItem("BillingState").Value
Me.txtBillingPostalCode.Text = oItem("BillingPostalCode").Value
Exit For
Next oItem End Sub
Private Sub cmdUpdate_Click()
If Not oItem Is Nothing Then
oItem("Name").Value = Me.txtName.Text
oItem("BillingStreet").Value = Me.txtBillingStreet.Text
oItem("BillingCity").Value = Me.txtBillingCity.Text
oItem("BillingState").Value = Me.txtBillingState.Text
oItem("BillingPostalCode").Value = Me.txtBillingPostalCode.Text
' *** The program hanges when the .Update routine is executed against the item ***
oItem.Update
End If
End Sub
Really odd. I was able to duplicate the problem as well. I tried using the \ character first, which works when there is a single quote in the field value. It doesn't hang, but you end up with \& instead of just &. Sorry, no ideas here.
Mike
As a workaround, can you try inserting a space in front of the &
The API will just trim the space for you, and it should get you around this bug.