function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rishav Dutta 12Rishav Dutta 12 

Printing a list inside HTML Email body

I have a list that I am passing to a function to send email. In the email I want to iterate the list but somehow unable. When debug logs are enabled I can see the list size properly, but somehow only the first value is printing. Can anyone help me out?
 
for (User user1 : userList)
    {   
         mail.setHtmlBody(user1.Id + '\t \n');
    }
E Jayaraman IyerE Jayaraman Iyer
Hi Rishav,

Only first value is getting printed because you are directly setting the htmlBody inside for loop. On every iteration you will need to append the Id to the previous value. Something like this : 
 
String str_userId = ' ';

for(User user1 : userList) {
     str_userId += user1.Id + '\t \n';
}

mail.setHtmlBody(str_userId );

I hope this helps. Let me know if there are any issues.

Thanks
SandhyaSandhya (Salesforce Developers) 
Hi,

Try to put debug statement for printing each value  user1 in for loop and check if the values are printing.

system.debug('Id' +user1.Id);


Best Regards,
Sandhya