You need to sign in to do that
Don't have an account?
scottskiblack
ASP.NET with VB.NET create case help
I am trying to create a new case with a form on a web page (ASP.NET with VB.NET). The code behind to process the form and insert is as follows. Fails at Try creating the case.
Dim binding As sforce.SforceService
binding = Nothing
Dim SFLogin As New Main
SFLogin.login()
'First we will create an account object array, all calls are batch
'ours is a single element batch
Dim SFDCcases(1) As sforce.sObject
Dim SFcase As sforce.Case = New sforce.Case
'instantiate the new account object
Dim qr As sforce.QueryResult = Nothing
'Set several properties
SFcase.First_Name__c = FirstName.Text
SFcase.Last_Name__c = LastName.Text
SFcase.Street_Address__c = Address.Text
SFcase.City__c = City.Text
SFcase.State_Province__c = State.Text
SFcase.Postal_Code__c = Zip.Text
SFDCcases(0) = SFcase
Dim saveResults() As sforce.SaveResult = Nothing
Try
saveResults = binding.create(SFDCcases) ' ERROR Object reference not set
' to an instance of an object.)
Catch ex As Exception
ERRORTXT.Text = ex.Message
recordType.Text = ex.Source
status.Text = ex.StackTrace
End Try
Dim binding As sforce.SforceService
binding = Nothing
Dim SFLogin As New Main
SFLogin.login()
'First we will create an account object array, all calls are batch
'ours is a single element batch
Dim SFDCcases(1) As sforce.sObject
Dim SFcase As sforce.Case = New sforce.Case
'instantiate the new account object
Dim qr As sforce.QueryResult = Nothing
'Set several properties
SFcase.First_Name__c = FirstName.Text
SFcase.Last_Name__c = LastName.Text
SFcase.Street_Address__c = Address.Text
SFcase.City__c = City.Text
SFcase.State_Province__c = State.Text
SFcase.Postal_Code__c = Zip.Text
SFDCcases(0) = SFcase
Dim saveResults() As sforce.SaveResult = Nothing
Try
saveResults = binding.create(SFDCcases) ' ERROR Object reference not set
' to an instance of an object.)
Catch ex As Exception
ERRORTXT.Text = ex.Message
recordType.Text = ex.Source
status.Text = ex.StackTrace
End Try
I took out setting the binding to nothing after declaring it and yes it is still nothing when debugging.
What am I missing?
I'm new to VB.NET from PHP.
Thanks, again.
Protected Sub buttonPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonPost.Click
Dim binding As sforce.SforceService
Dim lr As sforce.LoginResult
If lr Is Nothing Then
Dim SFLogin As New Main
SFLogin.login()
End If
'First we will create an case object array, all calls are batch
'ours is a single element batch
Dim SFDCcases(1) As sforce.sObject
'instantiate the new case object
Dim SFcase As sforce.Case = New sforce.Case
'Set several properties
SFcase.First_Name__c = FirstName.Text
SFcase.Last_Name__c = LastName.Text
SFDCcases(0) = SFcase
Dim saveResults() As sforce.SaveResult = Nothing
Try
saveResults = binding.create(SFDCcases)
Catch ex As Exception
ERRORTXT.Text = ex.Message
recordType.Text = ex.Source
status.Text = ex.StackTrace
End Try
For i As Integer = 0 To saveResults.GetUpperBound(0)
'we will create a separate save result object for clarity
Dim saveResult As sforce.SaveResult = saveResults(i)
'check to see if the first create was a success
If saveResult.success Then
'the id that we passed should be the one we get back.
WriteLine("Case entered with id: " + saveResult.id)
Else
'an error occurred on this record
Dim [error] As sforce.Error = saveResult.errors(0)
WriteLine([error].message)
End If
Next
End Sub
Module quickstart
Private binding As apex.SforceService
Private lr As apex.LoginResult
Private records() As apex.sObject
.
.
.
.
.
'First we will create an account object array, all calls are batch
'ours is a single element batch
Dim accounts(1) As apex.sObject
'instantiate the new account object
Dim account As apex.Account = New apex.Account
'set the id, the id must always be set for an update
account.Id = accountID
'set the new name of the account
account.Name = newAccountName
'add the account to the array of objects
accounts(0) = account
'we are now ready to update the record
'create an array for the results
Dim saveResults() As apex.SaveResult = Nothing
Try
saveResults = binding.update(accounts)
Catch e As Exception
Console.WriteLine(e.Message + vbCrLf + e.StackTrace)
Return
End Try
For i As Integer = 0 To saveResults.GetUpperBound(0)
'we will create a separate save result object for clarity
Dim saveResult As apex.SaveResult = saveResults(i)
'check to see if the first update was a success
If saveResult.success Then
'the id that we passed should be the one we get back.
Console.WriteLine("Update account with id: " + saveResult.id)
Else
'an error occurred on this record
Dim [error] As apex.Error = saveResult.errors(0)
Console.WriteLine([error].message)
End If
Next
But I get the following error now:
UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService
Protected Sub buttonPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonPost.Click
Dim binding As sforce.SforceService
binding = New sforce.SforceService()
Dim SFLogin As New Main
SFLogin.login()
'First we will create an case object array, all calls are batch
'ours is a single element batch
Dim SFDCcases(1) As sforce.sObject
'instantiate the new case object
Dim SFcase As sforce.Case = New sforce.Case
'Set several properties
SFcase.First_Name__c = FirstName.Text
SFcase.Last_Name__c = LastName.Text
SFcase.Employee_Number__c = EmpNumber.Text
SFcase.Street_Address__c = Address.Text
SFcase.City__c = City.Text
SFcase.State_Province__c = State.Text
SFcase.Postal_Code__c = Zip.Text
SFcase.Country__c = Country.Text
SFcase.Phone__c = Phone.Text
SFcase.Mobile_Phone__c = Mobile.Text
SFcase.Fax__c = Fax.Text
SFcase.Email__c = Email.Text
SFcase.Company__c = Company.Text
SFcase.Department__c = Department.Text
SFcase.Division__c = Division.SelectedValue
SFcase.Salesforce_training__c = Training.Checked
SFcase.Title__c = Titletxt.Text
SFcase.Employee_Number__c = EmpNumber.Text
SFDCcases(0) = SFcase
Dim saveResults() As sforce.SaveResult = Nothing
Try
saveResults = binding.create(SFDCcases)
Catch ex As Exception
ERRORTXT.Text = ex.Message
recordType.Text = ex.Source
status.Text = ex.StackTrace
End Try
'For i As Integer = 0 To saveResults.GetUpperBound(0)
' 'we will create a separate save result object for clarity
' Dim saveResult As sforce.SaveResult = saveResults(i)
' 'check to see if the first create was a success
' If saveResult.success Then
' 'the id that we passed should be the one we get back.
' WriteLine("Case entered with id: " + saveResult.id)
' Else
' 'an error occurred on this record
' Dim [error] As sforce.Error = saveResult.errors(0)
' WriteLine([error].message)
' End If
'Next
End Sub
Like I said I am new to VB. I am totally confused on the binding. I do not see how to use this appropriately, can you give an example or something in more detail of how to use the binding that login sets up, so that it has the sessionID and the serverUrl?
An example would be really helpful.
Dim m As New Main
m = Session("main")
Dim validSession As Boolean = m.setupBinding(Request("sessionId"), Request("serverURL"))
If (validSession) Then
m.validated = m.validateUser(Request("userId"), m.positionId)
If (m.validated) Then
Session.Add("main", m)
End If
End If
I have got the VB.NET quickstart and used this code to try a form to insert a case as well as downloaded the asp examples too.
Does anyone have any useful tips to understand this subject?
I have a web page with a form to capture case information. I am trying to create a new case from this form using the enterprise WSDL in ASP.NET with VB.NET. When click submit the following code is executed, my main class and the function to create is followed. Login, works, everything seems to work fine when I debug, but no case is created in SFDC. Any suggestions?
Thanks for your patience! The error is there, missing a required field.
Hope this helps someone.