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
onCollectonCollect 

Problem inserting records into the Contacts Object

Hi,

I am having problem inserting records into the Contact's Objects. I am able to insert one record at a time. Any suggestions??

following is the code i am using for my inserts.

thanks

Private Sub InsertSF()

Dim str As String

Dim cons(0) As sObject

str = "select * from vwInsertToSalesForce where InsertToSF = '0' "

cmd = New SqlCommand(str, con)

con.Open()

dtr = cmd.ExecuteReader

Try

While dtr.Read()

Dim contact As Contact

 

For j As Integer = 0 To cons.GetUpperBound(0)

'For j As Integer = 0 To cons

'Declare a new contact object to hold our values

contact = New Contact

Console.WriteLine("the dtr value is " & dtr(j))

contact.PhysicianID__c = Convert.ToString(dtr("PhysicianId"))

contact.PhysicianID__cSpecified = True

contact.Salutation = Convert.ToString(dtr("Salutation"))

contact.FirstName = Convert.ToString(dtr("FirstName"))

contact.LastName = Convert.ToString(dtr("LastName"))

cons(j) = contact

Next

End While

' con.Close()

'Dim sr() As SaveResult = binding.create(cons)' call the create method passing the arry of tasks as sobjects

Dim sr() As SaveResult = binding.create(cons)

For j As Integer = 0 To sr.GetUpperBound(0)' loop throught the results looking for errors and successes

Console.WriteLine(sr.GetUpperBound(0))

Console.WriteLine("item: " & (j))

If sr(j).success Then

Console.WriteLine("a contact was created with an id of : " & sr(j).id)

dtr.Close()

str = "update vwInsertToSalesForce " & _

"set InsertToSF = '1'" & _

"where InsertToSF = '0' "

 

 

cmd = New SqlCommand(str, con)

cmd.ExecuteNonQuery()

con.Close()

 

 

End If

Next

con.Close()

Catch ex As Exception

Console.WriteLine(vbCrLf & "failed here " & vbCrLf & ex.Message)

Console.Write(vbCrLf & "Hit return to continue...")

End Try

End Sub

SuperfellSuperfell
What's the problem ?
onCollectonCollect
i want to insert all records where

str = "select * from vwInsertToSalesForce where InsertToSF = '0' "

but the process inserts one record at a timein the Contacts object.

thanks

 

SuperfellSuperfell
because you defined cons as an array of length 1
onCollectonCollect
thank you.
 
 
onCollectonCollect

hi,

i am trying to assign a value from contact (custom field) . but it doesn't recognize the parameter value being passed to the logonName.

cmd.Parameters.AddWithValue("@LogonName", contact.Sync_Username__c)

its giving following error.  ex.Message "Procedure 'AddPhysician' expects parameter '@LogonName', which was not supplied." String

suggestions??

thanks