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
randyew1randyew1 

SForceOfficeToolkit

I'm using version 2.0 of the SForceOfficeToolkit in a VB.NET application. I can programmatically log in to our production site. What I want to do is log in to our sandbox programmatically.
 
sf = CreateObject("SForceOfficeToolkit.SForceSession")
sf.Login("xxx@companyname.com","pw", False)
 
This works fine against our production. The following properties are populated:
 
sf.ServerURL
sf.OrganizationName
sf.SessionID
etc.
 
My question is, how do I get this code (or what do I need to add to this code) to get the SForceSession to point to our sandbox?
 
I thought of this, but it does not seem to work.
sf.SetServerUrl("https:tapp0.salesforce.com/005T0000000nLJo")  ' url of our sandbox
 
The properties above are not populated, even though the login seems to work.
 
It seems like SForceSession needs to be configured somehow to point to the sandbox, but I don't know how.
 
Any help is appreciated.
 
Thanks,
 
Randy
jmarinchakjmarinchak
 
I think you have to set the server URL *before* you login.  Try this -
 
Code:
sf = CreateObject("SForceOfficeToolkit.SForceSession")
sf.SetServerUrl ("https://test.salesforce.com/services/Soap/c/6.0")
sf.Login("xxx@companyname.com","pw", False)
 
Remember, your username and password are probably different in your sandbox.  My username for our sandbox looks different, xxx@companyname.com.xxxtest
 
Jeff
 


Message Edited by jmarinchak on 07-25-2008 05:37 AM
randyew1randyew1

You would think that would work, but for some reason, it doesn't. I'm now using that URL and my sandbox login, but still no luck.

The sf properties are still null.

It could be that my login string is incorrect, but I wouldn't know, because no exception is thrown, no matter what I set the string to be. I am using the same login that I use to directly log into the sandbox.

It's only when I execute this statement that I get an exception:

o = sf.CreateObject(sSFTableName)

where sSFTableName is "Account" or some other SF table.
 
Randy
randyew1randyew1
I should mention that if I test for whether the login returns true or false, that it returns false with the login string I'm using. So either the sandbox url is incorrect or the login string is incorrect (but I can login to the sandbox directly with it so I don't think it's the login string that's wrong).
randyew1randyew1
Mystery solved. You need to add a security token from the sandbox to the end of your password to enable login.
 
We have it turned off in our production environment, so it's not necessary there.
 
Thanks for your help.
 
Randy
jmarinchakjmarinchak
 
I know the code I posted works, here is the full test program.  If you set LoginTest to false, you get logged into your regular account.  If you set LoginTest to True, then you login to your sandbox.
 
Code:
Dim g_sfApi As SForceOfficeToolkitLib3.SForceSession3
Public LoginTest As Boolean
Public myusername As String
Public mypassword As String
Public myserverurl As String
Public mymessage As String


Sub MyMain()
    LoginTest = True
    If LoginTest = True Then
        myusername = "username@company.com.xxxtest"
        mypassword = "password + token"        'this might be different from below
        myserverurl = "https://test.salesforce.com/services/Soap/c/6.0"
    Else
        myusername = "username@company.com"
        mypassword = "password + token"        'this might be different from above
        myserverurl = "https://www.salesforce.com/services/Soap/c/6.0"
    End If
      
If SampleLogin(myusername, mypassword) = True Then
    mymessage = "Logged into: " & g_sfApi.ServerUrl
    MsgBox mymessage
    'CreateAccount
Else
    mymessage = "Login failed, " & g_sfApi.ServerUrl
    MsgBox mymessage
    'Unload Me
End If

End Sub

Public Function SampleLogin(Username, Password) As Boolean
    Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
    Debug.Print "Default URL: ", g_sfApi.ServerUrl
    
    If LoginTest = True Then
        g_sfApi.SetServerUrl (myserverurl)
        Debug.Print "New URL: ", g_sfApi.ServerUrl
    End If

    SampleLogin = g_sfApi.Login(Username, Password)
End Function

 


Message Edited by jmarinchak on 07-26-2008 02:09 AM