You need to sign in to do that
Don't have an account?
K Srikanth
Round robin test class
Can any one help test class for below trigger.
trigger AssignLeadsToQueue on Lead (before insert, before update){
if (trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
List<Group> queues = [
SELECT Id,
(Select Id, UserOrGroupId FROM GroupMembers Order By ID ASC)
FROM Group
Where Type = 'Queue'AND Name = 'High-Priority Leads'
];
// Get the index of the last lead assigned user in the queue
Lead_Round_Robin_Assignment__c lrr = Lead_Round_Robin_Assignment__c.getOrgDefaults();
Integer userIndex = (lrr.get('User_Index__c') == null || Integer.valueOf(lrr.get('User_Index__c')) < -1)
? -1 : Integer.valueOf(lrr.get('User_Index__c'));
if (queues.size() > 0 && queues.get(0).GroupMembers.size() > 0) {
Id queueId = queues.get(0).Id;
Integer groupMemberSize = queues.get(0).GroupMembers.size();
for (Lead l : Trigger.new) {
if ((l.LeadSource =='Moengage'||l.LeadSource =='Facebook Ads'|') && l.Status== 'New'&&l.CreatedById=='********') {
system.debug('inside it is coming');
Integer leadUserIndex = (userIndex + 1) >= groupMemberSize ? 0 : userIndex + 1;
l.OwnerId = queues.get(0).GroupMembers.get(leadUserIndex).UserOrGroupId;
userIndex = leadUserIndex;
}
}
// Update the custom settings user index with the last lead assigned user
lrr.User_Index__c = userIndex;
update lrr;
}
}
}
trigger AssignLeadsToQueue on Lead (before insert, before update){
if (trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
List<Group> queues = [
SELECT Id,
(Select Id, UserOrGroupId FROM GroupMembers Order By ID ASC)
FROM Group
Where Type = 'Queue'AND Name = 'High-Priority Leads'
];
// Get the index of the last lead assigned user in the queue
Lead_Round_Robin_Assignment__c lrr = Lead_Round_Robin_Assignment__c.getOrgDefaults();
Integer userIndex = (lrr.get('User_Index__c') == null || Integer.valueOf(lrr.get('User_Index__c')) < -1)
? -1 : Integer.valueOf(lrr.get('User_Index__c'));
if (queues.size() > 0 && queues.get(0).GroupMembers.size() > 0) {
Id queueId = queues.get(0).Id;
Integer groupMemberSize = queues.get(0).GroupMembers.size();
for (Lead l : Trigger.new) {
if ((l.LeadSource =='Moengage'||l.LeadSource =='Facebook Ads'|') && l.Status== 'New'&&l.CreatedById=='********') {
system.debug('inside it is coming');
Integer leadUserIndex = (userIndex + 1) >= groupMemberSize ? 0 : userIndex + 1;
l.OwnerId = queues.get(0).GroupMembers.get(leadUserIndex).UserOrGroupId;
userIndex = leadUserIndex;
}
}
// Update the custom settings user index with the last lead assigned user
lrr.User_Index__c = userIndex;
update lrr;
}
}
}
The below articles give a good insight into how coverage can be improved
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
Example test class code snippet which runs to create the queue
Ref: https://pradeep-dani.blogspot.com/2016/02/create-queue-in-sfdc-apex-test-class.html
Related: https://salesforce.stackexchange.com/questions/33455/assign-a-case-to-a-queue-in-apex-test-class
If this information helps, please mark the answer as best. Thank you