function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dipak@pvsDipak@pvs 

Error at the time of running Apex Test Class.

Hi,

 

I have written the following test class:

 

@isTest
public class Test_tgrActuator
{
    static testMethod void caseAssignmentAndEscalation_Test()
    {
        Case c = new Case();

        Account aa = new Account();
        aa.Name = 'Test';
        aa.Address__c = 'Kolkata';
        aa.Account_Number__c = '293848343';
        insert aa;
        
        User u = new User();
        u.lastname = 'TestUser';
        u.Username = 'TestUser@user.com';
        u.Alias = 'TUse';
        u.CommunityNickname = 'TestUse';
        //u.TimeZoneSidKey = '(GMT+05:30)';
        u.LocaleSidKey = 'English (United States)';
        u.EmailEncodingKey = 'General US & Western Europe (ISO-8859-1, ISO-LATIN-1)';
        u.LanguageLocaleKey = 'English';
        u.email = 'test@test.com';
        u.city = 'Kolkata';
        u.department = 'PPS';
        insert u;
       
        Case_Category__c caseCategoryParent = new Case_Category__c();
        Case_Category__c caseCategoryCaseSubType = new Case_Category__c();
        Case_Category__c caseCategoryMapType = new Case_Category__c();
        Case_Category__c caseCategoryMapSubType = new Case_Category__c();    
        //Attachment a = new Attachment();
        //List<Steps__c> s = new List<Steps__c>();
        
        Id id_1 = [Select Id from RecordType WHERE Name='Case Type'].Id;
        Id id_2 = [Select Id from RecordType WHERE Name='Case Subtype'].Id;
        Id id_3 = [Select Id from RecordType WHERE Name='Map Type'].Id;
        Id id_4 = [Select Id from RecordType WHERE Name='Map Subtype'].Id;
                        
        //aId = aa.Id;
        caseCategoryParent.RecordTypeId = id_1 ;
        caseCategoryParent.Name = 'Request';
        insert caseCategoryParent;
        
        caseCategoryCaseSubType.RecordTypeId = id_2 ;
        caseCategoryCaseSubType.Parent__c = caseCategoryParent.Id;
        caseCategoryCaseSubType.Name = 'Reset Password';
        insert caseCategoryCaseSubType;
        
        caseCategoryMapType.RecordTypeId = id_3;
        caseCategoryMapType.Parent__c = caseCategoryCaseSubType.Id;
        caseCategoryMapType.Name = 'Reset the Password of GSL Report';
        caseCategoryMapType.Department__c = 'PPS';
        insert caseCategoryMapType;        
        
        Assignment_Rule__c assignByLoc = new Assignment_Rule__c();
        assignByLoc.Name = 'Assign By Location';
        assignByLoc.Case_Category__c = caseCategoryMapType.Id;
        assignByLoc.Assign_By__c = 'Location';
        assignByLoc.Criteria__c = 'Kolkata';
        assignByLoc.Priority__c = 1;
        insert assignByLoc;
        
        Mail_To__c assignmentQueue = new Mail_To__c();
        assignmentQueue.Assignment_Rule__c = assignByLoc.Id;
        assignmentQueue.User__c = u.Id;
        
     }     
}

 

 

When I run this test class, I get the following error:

 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Locale: bad value for restricted picklist field: English (United States): [LocaleSidKey]

Is there any format to write time zone and locale picklist value in test class?

 

 

Any help will be appreciated.

Abhay AroraAbhay Arora

Try using below for locale

 

localesidkey = 'en_US',

 

If above solves your problem please mark post as closed