You need to sign in to do that
Don't have an account?
Can we iterate in SingleEmailMessage class
I am writing a batch class in which the last step is to send emails to assigned user , that these many " no.s" of tasks are needed to attended by him. So I want send email in which all tasks are mentioned . What challenge i am facing is how to get all those tasks iterated in the " SingleEmailMessage" class .
The code below for now sends different emails for every different task . What I want is to consolidate all tasks into one email to that user.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); for(integer k=0;k<accns.size();k++) { mail.setToAddresses(new String[] {'abhishek.pandey@sfclouds.com'}); mail.setReplyTo('abhishek.pandey@sfclouds.com'); mail.setSenderDisplayName('Saleforce Tasks'); mail.setSubject(accns[k].Subject); mail.setPlainTextBody('Below is the task created for you as respectively'); String sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm(); //System.debug('Base URL: ' + sfdcBaseURL ); mail.setHtmlBody('<br/><b>Status of task : ' + accns[k].Status +'<br/>Priority :'+accns[k].Priority +'<br/>Due Date :'+accns[k].ActivityDate+'</b><p>'+ '<b> To view your task : </b><a href='+sfdcBaseURL+'/'+accns[k].Id+'>click here.</a>'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }
I want below area to traversed with the list of all tasks assigned to user , when email is sent . That means no. of tasks is variable and changes for every other user.
mail.setHtmlBody('<br/><b>Status of task : ' + accns[k].Status +'<br/>Priority :'+accns[k].Priority +'<br/>Due Date :'+accns[k].ActivityDate+'</b><p>'+ '<b> To view your task : </b><a href='+sfdcBaseURL+'/'+accns[k].Id+'>click here.</a>');
Thanks......
why don't you iterate through tasks and generate proper body of all tasks;
string body = ''
for (iterate throught tasks)
{
body = body+'<br/><b>Status of task : ' + accns[k].Status +'<br/>Priority :'+accns[k].Priority +'<br/>Due Date :'+accns[k].ActivityDate+'</b><p> <br/><br/>'
}
...
mail.setHtmlBody(body);
....
All Answers
why don't you iterate through tasks and generate proper body of all tasks;
string body = ''
for (iterate throught tasks)
{
body = body+'<br/><b>Status of task : ' + accns[k].Status +'<br/>Priority :'+accns[k].Priority +'<br/>Due Date :'+accns[k].ActivityDate+'</b><p> <br/><br/>'
}
...
mail.setHtmlBody(body);
....
Thanks mark for suggestion just one more thing where should i write the iteration code ,
I hope before the "singleemailmessage" class and what is this ----- string body = '' -------(I mean to say what quotes signifies).
Thanks
yes, before the singleemailmessage function; however it can be in the same class.
just create a body first iterating through your tasks;
end then put one singleemailmessage code using body you created before
body is just a string variable with which you will create html body; and because you will create in iteration it has to be blank at the beggining , so string body = ''
Thanks it worked .....