0

I have below piece of code where I get below error. Here b is the List of blobs. Error

List index out of bounds: 3

Apex Code

for(integer i = 0; i <counter; i++)
{
   Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
   efa.setFileName('attachment.pdf');
   efa.setBody(b[i]); // List index out of bounds: 3

   lstFileAttachments.add(efa);
}
3
  • We need to see more code. How does counter get its value? Commented Feb 16, 2016 at 8:38
  • 2
    Instead of for(integer i = 0; i <counter; i++) use for(integer i = 0; i <b.size(); i++) in refer to prev question
    – kurunve
    Commented Feb 16, 2016 at 8:38
  • Superb. Yes incrementing i was the issue. Commented Feb 16, 2016 at 8:40

1 Answer 1

3

Instead counter use b.size()

for(integer i = 0; i <b.size(); i++)
{
   Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
   efa.setFileName('attachment.pdf');
   efa.setBody(b[i]);

   lstFileAttachments.add(efa);
}
1
  • @SFDC_Learner Most welcome..
    – Ratan Paul
    Commented Feb 16, 2016 at 10:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .