Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

System.IndexOutOfRangeException: Index was outside the bounds of the array

Asked by Caroline Brown Aug 5, 2021 1.7K views 5 answers
Share

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); List ids = 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.’


Your answer

5 Answers

Chanchal01 Latest answer

Answered on Mar 20, 2026

The excitement of meeting a beautiful stranger in the comfort of your hotel room is an experience like no other. Our Escorts in The Lalit Hotel bring that excitement to life with their enthusiastic and passionate approach to companionship. They genuinely love what they do and it shows in every touch and every kiss. They will make you feel like the most desirable man in the world. If you are ready for a thrilling adventure call us right now.


Was this helpful?

Hitv

Answered on Jun 28, 2025

The hitv app is optimized for mobile networks, supporting smooth playback even on slower internet connections.


Was this helpful?

Saumya Giri

Answered on Feb 17, 2025

If you are on a corporate trip, make sure to at least get to enjoy their sizzling time. Well, you can individuals able to go to our internet site, look, and find beautiful Escort in Punjabi Bagh. You can able to be unforgettable for a few hours.


Was this helpful?

Taylo Elle

Answered on Nov 20, 2024

To fix the System.IndexOutOfRangeException, ensure you're handling Salesforce query result paging properly. Check done status and use queryMore() with queryLocator to retrieve remaining records in chunks until done is true. Among Us

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.