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
  • 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. Sep 14 '18 at 9:54
  • Yes ,, you can use use system.assertEquals to verify it. Please select proper keyword while posting the question. Sep 14 '18 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.