sana khan
asked on
INVALID_LOGIN: Invalid username, password, security token; or user locked out.
Dim path_original As String = "C:\Booking Number\Accounts\Epicor Invoices\Source\"
Dim path_error As String = "C:\Booking Number\Accounts\Epicor Invoices\Error\"
Dim path_success As String = "C:\Booking Number\Accounts\Epicor Invoices\Completed\"
Dim parentId
Dim directoryName As New DirectoryInfo(path_original)
Dim dirFileName As IO.FileInfo() = directoryName.GetFiles()
Dim fsize = dirFileName.Length
'Console.WriteLine(fsize)
If (fsize > 0) Then
Dim dirReadFileName As IO.FileInfo
Dim logFileName As String = String.Format("log{0}.txt", Now.ToString("MMddyyyy_hhmmss"))
Using w As StreamWriter = File.AppendText("C:\Booking Number\Accounts\Epicor Invoices\logs\" + logFileName)
Dim sobj As SFDC.SforceService = New SFDC.SforceService
Try
Dim lr As SFDC.LoginResult = sobj.login("username", "password")
sobj.SessionHeaderValue = New SFDC.SessionHeader
sobj.SessionHeaderValue.sessionId = lr.sessionId
sobj.Url = lr.serverUrl
'Dim sobject As WebReference.sObject = New WebReference.sObject
Console.WriteLine(sobj.Url)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
For Each dirReadFileName In dirFileName
Try
Dim attachment As SFDC.Attachment = New SFDC.Attachment
Dim filenames = dirReadFileName.Name.Substring(0, dirReadFileName.Name.IndexOf("_"))
Dim filename_wout_ext = dirReadFileName.Name.Substring(0, dirReadFileName.Name.IndexOf("."))
Dim ext = dirReadFileName.Extension
Dim filefullname_error = filename_wout_ext + "_" + Now.ToString("MMddyyyy_hhmmss") + ext
Dim filefullname As String = dirReadFileName.Name
If (filenames.Length = 8) Then
'Dim resultset As WebReference.QueryResult = sobj.query("Select id, Rocky__booking_number__c from opportunity where Rocky__booking_number__c = '" + filenames + "'")
Dim resultset As SFDC.QueryResult
resultset = sobj.query("Select id, EPICOR_Booking_Number__c, Invoiced__c from opportunity where EPICOR_Booking_Number__c = '" + filenames + "'")
'resultset = sobj.query("Select id, Booking_number__c from opportunity where Booking_number__c = '" + filenames + "'")
If (resultset.size > 1) Then
Console.WriteLine("More than one booking id present")
Log("More than one booking Id present for " + filenames, w)
IO.File.Move(path_original + filefullname, path_error + filefullname)
FileSystem.Rename(path_error + filefullname, path_error + filefullname_error)
ElseIf (resultset.size < 1) Then
Console.WriteLine("No records found for booking Id " + filenames)
Log("No records found for booking Id " + filenames, w)
IO.File.Move(path_original + filefullname, path_error + filefullname)
FileSystem.Rename(path_error + filefullname, path_error + filefullname_error)
Else
Dim res As SFDC.sObject = resultset.records(0)
parentId = res.Id
Console.WriteLine(res.Id)
Dim flStream As FileStream = New FileStream(path_original + filefullname, FileMode.Open, FileAccess.Read)
Dim len = flStream.Length
Dim documentcontents(len) As Byte
Try
flStream.Read(documentcontents, 0, len)
attachment.Name = filefullname
attachment.Body = documentcontents
attachment.ParentId = parentId
Dim sr As SFDC.SaveResult = sobj.create(New SFDC.sObject() {attachment})(0)
flStream.Close()
If (sr.success) Then
Dim opp As SFDC.Opportunity = res
opp.Invoiced__c = True
opp.Id = res.Id
sobj.update(New SFDC.sObject() {opp})
Console.WriteLine("Successfully uploaded file " + filefullname)
' Ensure that the target does not exist.
If File.Exists(path_success + filefullname) Then
File.Delete(path_success + filefullname)
End If
IO.File.Move(path_original + filefullname, path_success + filefullname)
Log("Successfully uploaded file " + filefullname, w)
Else
Console.WriteLine("There was an error creating the attachment." + System.Environment.NewLine + System.Environment.NewLine + "Message: " + sr.errors(0).message)
IO.File.Move(path_original + filefullname, path_error + filefullname)
FileSystem.Rename(path_error + filefullname, path_error + filefullname_error)
Log("There was an error creating the attachment." + System.Environment.NewLine + System.Environment.NewLine + "Message: " + sr.errors(0).message, w)
EmailLog("Invoice log", "Please find attached the logfile", logFileName)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End If
Else
Console.WriteLine("There was an error creating the attachment." + System.Environment.NewLine + System.Environment.NewLine + "Message: Epicor booking number not equal to 8")
IO.File.Move(path_original + filefullname, path_error + filefullname)
FileSystem.Rename(path_error + filefullname, path_error + filefullname_error)
Log("There was an error creating the attachment." + System.Environment.NewLine + System.Environment.NewLine + "Message: Epicor booking number not equal to 8", w)
EmailLog("Invoice log", "Please find attached the logfile of the invoice import.", logFileName)
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Next
End Using
End If
End Sub
When posting a problem make sure to specifically state your problem and as of error state the error as well as potion of code which the error point to. Without that its may take time to get help or sometime don't even get help because your post lake details of the problem.
To update your credentials and resolve this error, please complete the steps mention here: https://help.formassembly.com/help/467668-salesforce-error-invalid-login
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.