Activity Forums Salesforce® Discussions How can I test Messaging.MassEmailMessage with checking targetobjectids in Salesforce?

  • How can I test Messaging.MassEmailMessage with checking targetobjectids in Salesforce?

    Posted by Prachi on December 9, 2019 at 6:26 pm

    We have some User with UserRole. I need to verify that the email has been sent to the user with the role 'TestRole'. How can I do that?
    I try:

    List<Messaging.MassEmailMessage.targetobjectids> emails = [SELECT Id FROM User
    WHERE Id =: createUser('TestRole').Id];

    Deepak replied 5 years ago 3 Members · 2 Replies
  • 2 Replies
  • Nikita

    Member
    December 10, 2019 at 6:49 am

    Hi,

    ou are using "List" just add your email address to the list so you will also get one copy of that mail.
    Please check below code (below skeleton for your reference):

    Messaging.MassEmailMessage massEmail = new Messaging.MassEmailMessage();
    massEmail.setTargetObjectIds(userIds);
    massEmail.setSaveAsActivity(false);
    massEmail.setTemplateId(templateId);
    List<Messaging.Email> emails = new List<Messaging.Email>{massEmail};
    emails.add('your email id');
    Messaging.SendEmailResult[] results = Messaging.sendEmail(emails, false);

    You can change user emailid and you can provide your email id. But your user will get notification about emailid change

  • Deepak

    Member
    December 10, 2019 at 1:59 pm

    Messaging.MassEmailMessage massEmail = new Messaging.MassEmailMessage();
    massEmail.setTargetObjectIds(userIds);
    massEmail.setSaveAsActivity(false);
    massEmail.setTemplateId(templateId);
    List<Messaging.Email> emails = new List<Messaging.Email>{massEmail};
    emails.add(‘your email id’);
    Messaging.SendEmailResult[] results = Messaging.sendEmail(emails, false);

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos