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
Hema YejjuHema Yejju 

Unable to write test method for assigning Queue to the OwnerId field


I have the below code for Sales Object..there is a field called 'Dis type' on sales object and api name is 'Dis_Type__c'

in the Sales record page if user selects  Dis type as ' CallBck' the status of the record should be in working and in the same record 
owner id should be assigned to Queue...Where owner id is Lookup(user,Group);

 if(cs.Dis_Type__c == 'Callbck' ){
                   system.debug('cs.Disposition ' +cs.Disposition_Type__c);
                   List<Group> abcQueue = [select Id,Name from Group where Type = 'Queue'];
                   for(Group que : abcQueue){
                           if(que.Name == 'Sales Queue'){
                               cs.OwnerId = que.Id;
                               
                           }
                      }
                 
                 }
                 
                Can any one help me to write test method for this ?
AbhinavAbhinav (Salesforce Developers) 
Is you test data matches the first conditions   if(cs.Dis_Type__c == 'Callbck' )? 
mukesh guptamukesh gupta
Hi Hema,

Please follow below code:-
 
@IsTest 
public class TestForQueue {
    static testMethod void validateTestForQueue() {
        //Creating Group
        Group testGroup = new Group(Name='QUEUE NAME', Type='Queue');
        insert testGroup;
        
        //Creating QUEUE
        System.runAs(new User(Id=UserInfo.getUserId()))
        {
       /////////   INSERT YOUR SALES OBJECT HERE /////////
            //Associating queue with group AND to the Case object
            QueuesObject testQueue = new QueueSObject(QueueID = testGroup.id, SObjectType = 'Case');
            insert testQueue;
        }
        
       
    }
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh