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);
}
  • We need to see more code. How does counter get its value? – Sander de Jong Feb 16 '16 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 Feb 16 '16 at 8:38
  • Superb. Yes incrementing i was the issue. – Testing_SFDC Feb 16 '16 at 8:40
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);
}
  • @SFDC_Learner Most welcome.. – Ratan Paul Feb 16 '16 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.