You need to sign in to do that
Don't have an account?
rmcubed
problems creating contracts (VB.NET)
first post to this forum! I am seeing some odd behaviour when trying to create a contract. Basically, a whole bunch of fields do not show up with values, even though no error is generated, and I can see the values prior to the create call.
For example, the contract created by my test case below does not end up having a start date or an end date or a contract term. In more complex examples, it also applies to some of my custom fields. Can anyone verify this on their set-up, and/or suggest any solutions?
Here's the code:
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim sfSession As sforce.SforceService
Dim sfcs(0) As sforce.Contract
Dim sfR(0) As sforce.SaveResult
sfcs(0) = New sforce.Contract
sfcs(0).Name = "Test contract"
sfcs(0).StartDate = #1/1/2004#
sfcs(0).ContractTerm = 24
'use any known AccountID here
sfcs(0).AccountId = "001200000022brN"
'use your own values for the login
sfSession = Login(txtSFUsername.Text, txtSFPassword.Text)
sfR = sfSession.create(sfcs)
If sfR(0).success Then
Trace.WriteLine("Success - ID " & sfR(0).id)
Else
Trace.WriteLine("Failure: " & sfR(0).errors(0).message)
End If
MsgBox("Complete")
End Sub
Private Function Login(ByVal Username As String, ByVal Password As String) As sforce.SforceService
Dim sfSession As New sforce.SforceService
Dim objSFloginRes As sforce.LoginResult
objSFloginRes = sfSession.login(Username, Password)
sfSession.SessionHeaderValue = New sforce.SessionHeader
sfSession.SessionHeaderValue.sessionId = objSFloginRes.sessionId
sfSession.Url = objSFloginRes.serverUrl
Return sfSession
End Function
For example, the contract created by my test case below does not end up having a start date or an end date or a contract term. In more complex examples, it also applies to some of my custom fields. Can anyone verify this on their set-up, and/or suggest any solutions?
Here's the code:
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim sfSession As sforce.SforceService
Dim sfcs(0) As sforce.Contract
Dim sfR(0) As sforce.SaveResult
sfcs(0) = New sforce.Contract
sfcs(0).Name = "Test contract"
sfcs(0).StartDate = #1/1/2004#
sfcs(0).ContractTerm = 24
'use any known AccountID here
sfcs(0).AccountId = "001200000022brN"
'use your own values for the login
sfSession = Login(txtSFUsername.Text, txtSFPassword.Text)
sfR = sfSession.create(sfcs)
If sfR(0).success Then
Trace.WriteLine("Success - ID " & sfR(0).id)
Else
Trace.WriteLine("Failure: " & sfR(0).errors(0).message)
End If
MsgBox("Complete")
End Sub
Private Function Login(ByVal Username As String, ByVal Password As String) As sforce.SforceService
Dim sfSession As New sforce.SforceService
Dim objSFloginRes As sforce.LoginResult
objSFloginRes = sfSession.login(Username, Password)
sfSession.SessionHeaderValue = New sforce.SessionHeader
sfSession.SessionHeaderValue.sessionId = objSFloginRes.sessionId
sfSession.Url = objSFloginRes.serverUrl
Return sfSession
End Function
In .NET you need to set an additional property for intrinsic data types. You'll notice that your StartDate field has a "sister" field called StartDateSpecified. Setting that field to true while also setting your StartDate field will cause correct create/update behavior.
What I mean is types in .net that can't be set to null.