Requirement: Send an Email alert using a custom lightning component for selected records under few circumstances(Business logic) for which Messaging.sendEmail was used. Functionality working completely fine.

Challenge: Now the problem is when the test class gets executed. I am creating a list of users and assigning the permission set in the test setup. I used System.runAs(quriedUsers) to run a test block and getting following error:-

Insert Failed, Invalid Email Address and while debugging further I analyzed the email and name field are not exactly the same as I initialized under test class. I am getting like automatedclean@00d3o0000008cbiuai as an email that is not under the correct format.

Any workaround excluding if(Test.isRunningTest()){}

Thanks Pranav


automatedclean@00d3o0000008cbiuai this email format is similar to email format for Data.com Clean user. You can not view this user in salesforce UI. When you query user record in salesforce, it returns this user.

enter image description here

I believe this user is being used for running the Test block.

How to get users that are created in test class setup?

Answer: Make the query on User and filter the specific user that you created in the test block. you may use the following:-

SELECT Id, Name, Username FROM User ORDER BY CreatedDate DESC LIMIT 1

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.