You need to sign in to do that
Don't have an account?
divya1234
Test Classes are getting failed due to validation rule on user object
I wrote the validation rule on user object for picklist field value should be A, B,C. now my test classes are getting failed.can i just add one line user.picklist__c = 'A", before user record get an insert or i need to add a line for each picklist value.i.e user.picklist__c = 'A"user.picklist__c = 'B"user.picklist__c = 'C"
Add user.picklist__c = 'A" on user record and run testclass
Hope it helps you.
Please let me know in case of any other help.
Thanks
Varaprasad
May I suggest you please refer the below link to reference.
- https://developer.salesforce.com/forums/?id=906F00000008yyzIAA
Hope it helps.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
Create one helper class and then call it wherever you need like below :
In your test class use below code :
user us = userTest.cretUser();
System.runAs(u) {
//Add your Test code here
}
Hope it helps you.
Thanks
Varaprasad
public static testMethod void testAccountPhoneFax(){
TestHelper.createCustomSettings();
setupData();
TestClassHelper.CreateUser();
System.runAs(u)
{
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId());
}
Use below line instead of TestClassHelper.CreateUser();
user u = TestClassHelper.CreateUser();
Hope it helps you.
Thanks
varaprasad
user u = TestClassHelper(---) ,what should be argument ..this is my helper class do i need 2 methods
@isTest
Public class TestClassHelper
{
public static User CreateUser()
{
//Get a profile id from the data base to assign to our user in this case make them a sys admin
Profile p = [select id from profile where name='System Administrator'];
//Create a new sys admin user and do an insert
User u = new User(alias = 'standt', email='noEmail@testorg.com',
emailencodingkey='UTF-8', lastname='Testo', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='MrTestUser@testorg.com',Resource_Type__c='Employee');
User u1 = [Select u.Profile.Name, u.ProfileId, u.Name, u.Id From User u where u.Profile.Name = 'System Administrator' limit 1];
return u;
}
public User CreateUser(string userType)
{
//Get a profil id from the data base to assign to our user in this case make them a sys admin
Profile p = [select id from profile where name=:userType];
//Create a new sys admin user and do an insert
User ur = new User(alias = 'standt', email='noEmail@testorg.com',
emailencodingkey='UTF-8', lastname='Testo', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='MrTestUser@testorg.com',Resource_Type__c='Employee');
return ur;
}
}
You can call like below:
TestClassHelper tc = new TestClassHelper();
User usr = tc .CreateUser('System Administrator');
Hope it helps you.
Thanks
varaprasad