I have an Apex class on Custom Object Called QueueDistroHelper__c
What I am basically doing is getting the Queue Id from a custom field(Related_Queue_Id__c) on the Custom object
Querying all the users in that queue
And updating another custom field(Queue_Members__c ) with all the users in that Queue
My apex class is working fine
Here is the apex class -
global class lookUpAccountAnnotation {
public class inputValues{
@InvocableVariable(label='Queue ID' )
public string QueueId;
@InvocableVariable(label='Record Id' )
public Id recordid;
public string temp;
}
@InvocableMethod
public static void deletePackageLicense(List<inputValues> inputs){
for (inputValues i : inputs)
{
List<QueueDistroHelper__c> getcurrentobject = [SELECT Queue_Members__c , Next_Queue_Reassignment_User__c FROM QueueDistroHelper__c WHERE Id=:i.recordid ];
List<User> users = [SELECT
name
FROM
user
WHERE
id IN ( SELECT userOrGroupId FROM groupmember WHERE groupId =:i.QueueID)
AND
isActive = true
];
for ( User test : users){
if(getCurrentObject != null && !getCurrentObject .isEmpty()) {
if(getCurrentObject[0].Queue_Members__c == null)
getCurrentObject[0].Queue_Members__c = '';
getCurrentObject[0].Queue_Members__c = getCurrentObject[0].Queue_Members__c + ' ' + test.name;
}
getCurrentObject[0].Next_Queue_Reassignment_User__c =+ users.get(1).name;
getCurrentObject[0].Last_Queue_Reassignment_User__c =+ users.get(0).name;
update getcurrentobject[0];
}
}
}
}
I am trying to make a test class for the same , Here are the steps I am doing for testing
Creating 4 test users
Adding those users in a test queue
Updating my fields on my Custom object with User name and Queue ID
Not sure if its the right approach
Here is my test Class -
@isTest
private class lookUpAccountAnnotation_Test{
@TestSetup
static void setup() {
// Setup 4 Test Users
Group grpObj = new Group(Type='Queue', Name='Test Queue1');
insert grpObj;
QueueSObject qObj = new QueueSObject(SobjectType='Lead', QueueId=grpObj.Id);
insert qObj;
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
List<User> users = new List<User>();
while (users.size() < 5) {
Blob b = Crypto.GenerateAESKey(128);
String h = EncodingUtil.ConvertTohex(b);
String uid = h.SubString(0,8);
//insert 4 test users
User u = new User(Alias = uid, Email= uid + '@myorg.com',
EmailEncodingKey='UTF-8',LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/New_York', UserName= uid + '@myorg.com');
ID gr = [SELECT Id FROM Group WHERE Name = 'Test Queue1'].Id;
ID us = [SELECT Id , Name FROM User WHERE LastName='Testing'].Id;
//Add one user in a test queuecreated above
GroupMember gm = new GroupMember(GroupId = gr, UserOrGroupId = us);
insert gm;
}
System.Test.startTest();
QueueDistroHelper__c q = new QueueDistroHelper__c();
insert q;
//insert user name and Queue ID in custom Object
q.Related_Queue_Id__c = grpObj.Id;
q.Queue_Members__c = users.get(1).Name;
lookUpAccountAnnotation l = new lookUpAccountAnnotation();
//queryHelper q = new QueueDistroHelper__c(Name='TestQuery' , Queue_Members__c=users.name);
System.Test.stopTest();
}
}