Professional > Interview scripting > Using Interview Services > Salesforce Interview Service > Accessing the Salesforce service from mrScriptBasic
 
Accessing the Salesforce service from mrScriptBasic
The following script demonstrates how the Salesforce.com service can be used outside of the Interview Services framework. The following mrScriptBasic script demonstrates how to create and configure the service and then creates a Salesforce.com client object to query for the first and last names of all contacts. The results of the query are output to the console.
Replace the script's service.Username and service.Password values with valid values in your script.
Dim service
Dim client
Dim qr ' QueryResult
Dim done
Dim record
Dim fname
Dim lname
Dim iCnt

Set service = CreateObject("SalesforceService.Service")
service.URL = "https://login.salesforce.com/services/Soap/u/24.0"
service.Username = "developer@unicomsi.com"
service.Password = "xxxxxxxxPV8aBKpX2h5BwRBdjf8pQmzX"
Set client = service.ClientFactory.CreateClient() ' Auto logs the client in

' We are going to increase our return batch size to 250 items
' Setting is a recommendation only, different batch sizes may
' be returned depending on data, to keep performance optimized.
client.QueryOptionsValue.batchSize = 250
client.QueryOptionsValue.batchSizeSpecified = true

Set qr = client.query("select FirstName, LastName from Contact")
done = false

iCnt = 0
If (qr.size > 0) Then
Debug.Echo("User can see " + CText(Len(qr.records)) + " contact records.")

While Not done
Debug.Echo("")
For Each record in qr.records
' When using the Enterprise WSDL could convert the returned sObject
' to a Contact and use the properties of that. When using the
' Partner WSDL only have access to generic fields.
fName = record.fields[”FirstName”]
lName = record.fields[”LastName”]
If (fName = "") Then
Debug.Echo("Contact " + CText(iCnt + 1) + ": " + lName)
Else
Debug.Echo("Contact " + CText(iCnt + 1) + ": " + fName + " " + lName)
End If
iCnt = iCnt + 1
Next

If (qr.done) Then
done = true
Else
qr = client.queryMore(qr.queryLocator)
End If
End While
Else
Debug.Echo("No records found.")
End If

Set client = Null
Set service = Null
See also
Accessing the Salesforce service from the interview routing script
ISalesforceService interface
Salesforce Interview Service