February 3, 2012

How to send email to a public group using apex?

Sample Code:

  public List<String> getMailAddresses()
  List<String> mailList = new List<String>();
  List<String> mailAddresses = new List<String>();
  Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'SFDC'];
  for (GroupMember gm : g.groupMembers)
  User[] usr = [SELECT email FROM user WHERE id IN :mailList];
  for(User u : usr)
  return mailAddresses;

No comments:

Post a Comment