You need to sign in to do that
Don't have an account?

Future method not updating test users
I have a class that fixes sandbox user emails and a test class that inserts users than calls the method to fix the emails. This code works if I just run it but cant get it to work on the test data. Anything Im missing? It fails on the assert.
//Fix emails of the admin users on the sandboxs automatically public class FixSandboxUsers { @future public static void FixUsers(){ //make sure its a sandbox enviroment if([SELECT IsSandbox FROM Organization LIMIT 1].IsSandbox){ //get the system admin profile Profile p = [Select id, name from Profile where name='System Administrator' limit 1]; //check users with that profile List<User> use = [Select id, name, email, Profileid from user where profileid = :p.id]; //update each users email for(User u : use){ u.email = u.Email.replace('=','@').replace('@example.com',''); //debug print out the email // System.debug(u.Email); } //update the users update use; } } }
@isTest public class FixSandboxUsers_Test { @isTest public static void FixUsers_Test(){ Profile profileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator' LIMIT 1]; List<User> userList = new List<User>(); for(integer i = 0; i < 10; i++){ userList.add(new User(LastName = 'LIVESTON' + i, FirstName='JASON' + i, Alias = 'jliv' + i, Email = 'TESTADDRESS' + i + '=asdf.com@example.com', Username = 'TESTADDRESS' + i + '@asdf.com', ProfileId = profileId.id, TimeZoneSidKey = 'GMT', LanguageLocaleKey = 'en_US', EmailEncodingKey = 'UTF-8', LocaleSidKey = 'en_US' )); } insert userList; Test.startTest(); FixSandboxUsers.FixUsers(); Test.stopTest(); For(User u : userList){ System.debug(u.Email); System.assert(!u.email.contains('=')); System.assert(!u.email.contains('@example.com')); } } }
Let us know if this will help you
All Answers
Let us know if this will help you