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
Jithesh VasudevanJithesh Vasudevan 

How to set the owner type for Case in a test class ? I have set the Owner to the case against the dummy user I have created. But can't set the owner type for it and it gives me a null value because of that.

  Profile p= [Select Id from profile where Name='System Administrator'];
        User u=new User(firstname = 'ABC', 
                        lastName = 'XYZ', 
                        email = 's-abe=kureha.co.jp@example.com', 
                        Username = 's-ab@kureha.co.jp.sd', 
                        EmailEncodingKey = 'ISO-8859-1', 
                        Alias = 'ShAbe',
                        IsActive=true,
                        TimeZoneSidKey = 'America/Los_Angeles', 
                        LocaleSidKey = 'en_US', 
                        LanguageLocaleKey = 'en_US', 
                        ProfileId = p.Id);
        insert u;   
        Case c = new Case(Status='New',OwnerId=u.Id);     
        insert c; 
Raj VakatiRaj Vakati
Use this code
 
Id caseRecTypeId = TestDataUtilities.getRecordTypeId('Case','My Record Type 1');        

    case caseRec = new case();

    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = false;
    dmo.assignmentRuleHeader.assignmentRuleID = null;
    caseRec.setOptions(dmo);

    caseRec.RecordTypeId = caseRecTypeId;
    caseRec.AccountId = '';
    caseRec.Status = 'Open';
	 Group queueName = [SELECT Id,Name from Group where Name ='Delete Queue' and Type='Queue'];
    caseRec.OwnerId = queueName.Id;
	
	

    Database.SaveResult sr = Database.insert(caseRec, dmo);