About this question
I am trying to fetch all the attachments for a record from salesforce by .Net webservice.
Below is the code which I am was used. When I was fetching a single attachment, didn’t faced any issue. But when I tried to fetch multiple attachment,it is giving me the below error -
'System.IndexOutOfRangeException: Index was outside the bounds of the array. at WcfService1.Service1.ConnectSalesforce() in C:UsersmohapatssourcereposWcfService1WcfService1Service1.svc.cs:line 149 at WcfService1.Service1.CombineMultiplePDFs(List`1 InFiles, String OutFile) in C:UsersmohapatssourcereposWcfService1WcfService1Service1.svc.cs:line 59'
c# code -
if(currentLoginResult.sessionId != null) { QueryResult queryResult = null; String SOQL = "SELECT Id FROM Attachment where ParentId = '0010v0000071CHp'"; queryResult = sfdcBinding.query(SOQL); Listids = new List (); if (queryResult.size > 0) { for(int i = 0; i < queryResult xss=removed> 0) { //QueryResult queryResult1 = null; //String SOQL1 = "SELECT Id,Body,Name FROM Attachment where Id = '" + ids + "'"; //queryResult1 = sfdcBinding.query(SOQL1); String query = "SELECT Id,Body,Name FROM Attachment "; String strIds = ""; foreach (String id in ids) { if (strIds.Equals("")) { strIds = "'" + id + "'"; } else { strIds += ",'" + id + "'"; } } query += "where id in (" + strIds + ")"; QueryResult result = sfdcBinding.query(query); Boolean done = false; if (result.size > 0) { while (!done) { sObject[] records = result.records; for (int i = 0; i < records xss=removed xss=removed xss=removed>
The below soql -
QueryResult result = sfdcBinding.query(query);This should return two arrays
result.records[0] & result.records[1]but it is returning only one
result.records[0]but result.size is showing as 2
So at the below line
Attachment q = (Attachment)result.records[i];when it comes for the 2nd time, it throws the above error.
Kindly help how can I resolve this system.indexoutofrangeexception: 'index was outside the bounds of the array ‘ error.’