I need some help

I was advised to create a test apex class to test my logic. This conversation can be seen here -- > enter link description here

I created the following test apex however I get an error message

Apex Test Result Detail
Time Started 25/04/2014 16:36 Class DeactivateUsers_Test Method Name testuserdeactivate Pass/Fail Fail Error Message System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Users may only be granted full System Administrator profile with the approval of Kamaljit. Please select Sys Admin (ex Japan).: [] Stack Trace Class.DeactivateUsers_Test.testuserdeactivate: line 52, column 1

Does anyone have any ideas, how I can overcome this ??

-----Apex Code -----

`enter preformatted text here`
private class DeactivateUsers_Test {

static testMethod void testuserdeactivate() {

List<User> tobeadded = new List<User>();
//enter the profile name below that you want to set for the test users.
Profile prof = [select id from profile where name='System Administrator'];

//make sure to add/remove the fields below that are required at your company to create  new users

//create test user 3
User u3 = new User();
//u3.email = 'u3user@' + mydomain;
u3.lastname = 'tester';
u3.firstname = 'u3user';
u3.alias = 'u3user';
u3.profileid = prof.Id;
u3.isactive = False;
u3.Inactive_Date__c = null;
//u3.username='u3user@' + mydomain;

//add test user to the tobeupdated list
//create user 4
User u4 = new User();
//u4.email = 'u4user@' + mydomain;
u4.lastname = 'tester';
u4.firstname = 'u4user';
u4.alias = 'u4user';
u4.profileid = prof.Id;
u4.isactive = False;
u4.Inactive_Date__c = null;
//u4.username='u4user@' + mydomain;
//add test user to the tobeupdated list

//insert the list of new users
insert tobeadded;
//verify the users were inserted
List<User> insertedlist = [select Id,Email,isactive from User Where CreatedDate =   Today];
System.debug('list includes: ' + insertedlist);
//test the scheduled class
DeactivateUsers sh1 = new DeactivateUsers();
       String sch = '0 0 23 * * ?';
       system.schedule('Test DeactivateUsers data', sch, sh1);

1 Answer 1


It appears that there is a validation rule set in the org. Based on the message "Kamaljit" should know why. That error message may also be suggesting to use the profile "Sys Admin (ex Japan)" instead.

But most users are not "System Administrators" so probably a less privileged profile is what the test should be using. That would (hopefully) not trigger the validation rule.

You must log in to answer this question.

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