0

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];

And then use assertEquals. But it's not worked of caurse.

1 Answer 1

1
  • You 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
2
  • It's a test class :) I need to use then System.assertEquals(UserRole.Name, 'TestRole'); - a user, who get the message. Commented Sep 14, 2018 at 9:54
  • Yes ,, you can use use system.assertEquals to verify it. Please select proper keyword while posting the question.
    – Annappa PH
    Commented Sep 14, 2018 at 9:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .