You need to sign in to do that
Don't have an account?
Creating Dynamic Apex Query to populate String for outbound email message...
Hi,
If anyone has experience with dynamic Apex and SendEmailMmessage, i would appreciate some help on a quick question. I am looking to create a Dynamic APEX Query within a SingleEmailMessage and having trouble getting the query to populate the list, and also how to associate the results of the query with the toAddresses string. So far I have the two parts of my class below. Any advice on how to put them together?
List<sObject> L = Database.query(' SELECT Member_Email__c FROM Attendee__c WHERE Dining_paid__c = false
LIMIT 100'
String[] toAddresses = new String[] {'bobfossil@hotmail.com'};
Thanks,
Bob
Might I suggest that you may not need to use dynamic SOQL (which will overcomplicate things if not needed).
You could instead do:
List<Attendee__c> attendee_list = [SELECT Member_Email__c FROM Attendee__c WHERE Dining_paid__c = false LIMIT 100];
List<String> toAddresses = new List<String>();
for(Attendee__c a : attendee_list)
{
toAddresses.add(a.Member_Email__c);
}
All Answers
Might I suggest that you may not need to use dynamic SOQL (which will overcomplicate things if not needed).
You could instead do:
List<Attendee__c> attendee_list = [SELECT Member_Email__c FROM Attendee__c WHERE Dining_paid__c = false LIMIT 100];
List<String> toAddresses = new List<String>();
for(Attendee__c a : attendee_list)
{
toAddresses.add(a.Member_Email__c);
}
Eric, you are a star. Works a treat and helped me along with understanding the syntax. Thank you
No problem, glad it worked out.