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
CJDEVCONPROCJDEVCONPRO 

Correct way to Exit Sub when no account number is found.

I am trying to query an account number and when it is found I pop open Sforce. But when it is not found, I wish to do nothing.
 
the problem is I am getting an instance cannot be set error. Is this the correct way to check the records from the query? (See below)
 
Here is the code:
 

qr = binding.query("select id, accountnumber from Account where accountnumber = 1")

Dim bContinue As Boolean = True

Dim loopCounter As Integer = 0

While bContinue

loopCounter += 1

lstStatus.Items.Insert(0, Now() & " " & "Results Set " & Convert.ToString(loopCounter) & " - ")

For i As Integer = 0 To qr.records.GetUpperBound(0)

Dim c As sforce.sObject = qr.records(i)

Dim accountNum As String = getFieldValue("id", c.Any)

If accountNum Is Nothing Then

'NEED CODE FOR HERE

Else

'Pop open SForce.com

End If

bouscalbouscal
You actually need to check to see if the result set has any records, looking at a field in a null result set will give you an error.
 

Code:

qr = binding.query("select id, accountnumber from Account where accountnumber = 1")

' Check for results - I'm not sure how to check this

If qr.records.upperbound() = 0 then

     Exit Sub

End if

Dim bContinue As Boolean = True

Dim loopCounter As Integer = 0

While bContinue


 

CJDEVCONPROCJDEVCONPRO
It looks like this works so far.Code:
If (qr.size = 0) Then