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
SriniKSriniK 

API Call login question

Hi
 
We are using API call in our integration application which is in .net.  Is there any specific error code or message which specifically states that error was due to invalid username and or password. Based on which next steps would be taken like telling the user to re-enter his credentials.
 
Thanks
Srinik
Pat WimberlyPat Wimberly
From the stock code (.NET starter projects for API) they use exception type to make this distinction. It looks like we're assuming that if we get a coherent Soap response from the server that is nonetheless an error, it is probably a login problem. By extension, other types of errors indicate we were not able to get the server to acknowledge our attempt. The code I use is below, the relevant bit in blue.

        Public Function loginSalesForceServer(ByVal UserName As String, ByVal Password As String) As Boolean
        Dim loginRes As sforce.LoginResult

        Dim un As String = UserName
        If un.Length = 0 Then
            Return False
        End If

        Dim pw As String = Password
        If pw.Length = 0 Then
            Return False
        End If

        '/*
        '* Create the sfbinding to the sforce servics
        '*/
        sfbinding = New sforce.SforceService

        '// Time out after a minute
        sfbinding.Timeout = 60000

        Try
            loginRes = sfbinding.login(un, pw)
        Catch e As System.Web.Services.Protocols.SoapException
            '// This is likley to be caused by bad username or password
            Return False
        Catch ex As System.Exception
            '// This is something else, probably comminication
            Return False
        End Try

        sfSessionID = loginRes.sessionId
        sfServerURL = loginRes.serverUrl

        '//Change the sfbinding to the new endpoint
        sfbinding.Url = loginRes.serverUrl

        '//Create a new session header object and set the session id to that returned by the login
        sfbinding.SessionHeaderValue = New sforce.SessionHeader
        sfbinding.SessionHeaderValue.sessionId = loginRes.sessionId

        prvSalesForceLoginState = "Logged In"

        Return True
    End Function
SriniKSriniK

Thanks Pat for your time and effort.. 

Srinik