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
JJoshJLJJoshJL 

Querymore Problem

Hopefully this will be the last time I need to post for a while. In any case, having some difficulty with querymore. In my code, I can get it to work until I add in the following code.

updowner.Id = assetid

updowner.OwnerId = userid

conacc(0) = updowner

binding.update(conacc)

If I coment this one part out, the querymore option works without a problem, If I leave it in it dies with an invalid_query_locator error. Any help is appreciated as I am perplexed by this one..  API = 4.0    VB.net  Here is the section of code with a problem. Thanks in advance

Josh

While bContinue

 For b = 0 To qr.records.GetUpperBound(0)

 Dim l As salesforce.Assets__c = CType(qr.records(b), salesforce.Assets__c)

 assetid = l.Id

 accountid = l.Customer_Number__c

 soql2 = "select OwnerId from account where id = '" & accountid & "'"

 Try

  Dim qs As salesforce.QueryResult = Nothing

  binding.QueryOptionsValue = New salesforce.QueryOptions

  qs = binding.query(soql2)

  c = 0

  If qs.size > 0 Then

   For c = 0 To qs.records.GetUpperBound(0)

    Dim m As salesforce.Account = CType(qs.records(c), salesforce.Account)

    userid = m.OwnerId

   Next

  End If

  Catch ex As Exception

  MessageBox.Show(ex.Message)

 End Try

 Dim updowner As New salesforce.Assets__c

 Dim conacc(1) As salesforce.sObject

 updowner.Id = assetid

 updowner.OwnerId = userid

 conacc(0) = updowner

 binding.update(conacc)

 'MessageBox.Show(userid & " : " & userid)

 Console.WriteLine(b & ":" & l.Id & ":" & accountid & ":" & userid)

 Next

 If qr.done Then

 bContinue = False

 Else

 qr = binding.queryMore(qr.queryLocator)

 End If

End While

DevAngelDevAngel

Hi JJoshJL,

This may have to do with concurrent connections.  This topic is not completely clear to me, but, we might be able to modify your logic to overcome the problems you are having.

If during processing of the qr results, you "collect" the items you want to update inside the loop and then do a batch update outside the loop you may be able to overcome the problem.

'Set up your array of updates here
Dim conacc(0) As sforce.Assets__c()
While bContinue
For b = 0 To qr.records.GetUpperBound(0)
Dim l As salesforce.Assets__c = CType(qr.records(b), salesforce.Assets__c)
assetid = l.Id
accountid = l.Customer_Number__c
soql2 = "select OwnerId from account where id = '" & accountid & "'"
Try
Dim qs As salesforce.QueryResult = Nothing
Binding.QueryOptionsValue = New salesforce.QueryOptions
qs = Binding.query(soql2)
c = 0
If qs.size > 0 Then
For c = 0 To qs.records.GetUpperBound(0)
Dim m As salesforce.Account = CType(qs.records(c), salesforce.Account)
userid = m.OwnerId
Next
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim updowner As New salesforce.Assets__c
updowner.Id = assetid
updowner.OwnerId = userid
'add the updowner to your update array
conacc(conacc.GetUpperBound(0)) = updowner
'check to see if we are at the end of this query batch, and if not
'add another element to the end of the array is anticipation of the next loop
If b < qr.records.GetUpperBound(0) Then ReDim Preserve conacc(conacc.GetUpperBound(0) + 1)
'Echo you progress to the console
Console.WriteLine(b & ":" & l.Id & ":" & accountid & ":" & userid)
Next
If qr.done Then
bContinue = False
Else
qr = binding.queryMore(qr.queryLocator)
End If
End While
'Not that we have created an array of items to update,
Dim sr() As sforce.SaveResult = binding.update(conacc)
'update the whole batch and check the results.
For i As Integer = 0 To sr.GetUpperBound(0)
If sr(i).success Then
Console.WriteLine("asset updated: " + sr(i).id)
Else
Console.WriteLine("error updating asset: " + sr(i).id + " - " + sr(i).errors(0).message)
End If
Next

JJoshJLJJoshJL

Hey Dev,

   Thanks for the help. Querymore worked like it was suppose to, but there is still a timeout issue when it starts to try and load the accounts in. Ill look at it and hopefully will figure out what is going on.

Thanks for all your help.

Josh