• umesh kant
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi All,

I have developed an apex class whcih basically assign users to queue dynamically.I have a VF page which will launch from a custom VF tab.This VF page shows few users and with the checkbox.When checkbox against the username is marked and hit Save button then seleected users will go to the queue defined in class.
Below is my clas:
public class TodayTelesalesDetails {

public Date Today { 
    get { 
        return Date.today(); 
    }
}
public List<wrapAgent> wrapAgentList{get; set;}
public List<User> selectedAgents{get;set;}

public TodayTelesalesDetails (){
   
    if(wrapAgentList == null) {
        wrapAgentList = new List<wrapAgent>();

        for(User teleSalesAgent: [select Id, Name, Email from User where Name IN('Steve Waugh','Yuvraj Singh')]) {
            // As each agent is processed we create a new wrap object and add it to the wrapAgentList
            wrapAgentList.add(new wrapAgent(teleSalesAgent));
    }
}
}

public PageReference doFullSave(){

    set<id> userSetId = new set<id>();
    list<GroupMember> gmm = new list<GroupMember>();
    List<GroupMember> toBeDeleted= [SELECT Id, GroupId, UserOrGroupId FROM GroupMember where GroupId = '00G9D000000toPYUAY'];
    delete toBeDeleted;
    List<User> userlist=[select Id, Name from User where Name IN('Steve Waugh','Yuvraj Singh')];
   
    for(User u : userlist)
    { 
    system.debug('message3>>'+u);
         for(wrapAgent wrapAccountObj : wrapAgentList) {
             
            if(wrapAccountObj.selected == true) {
                userSetId.add(wrapAccountObj.teleAgent.id);
                
            }
        }

    }
      
    for(User us : [select id from User where id =: userSetId])
    {
       
        for(Group gg : [select id,name from Group where type = 'Queue' and Name = 'TeleSales Queue'])
        {
            GroupMember gm = new GroupMember();
            gm.groupId = gg.id;
            gm.UserOrGroupId = us.Id;
            gmm.add(gm);
        }
        
    }
            
     
    insert gmm;
    PageReference pageRef = new PageReference('/');
            pageRef.setRedirect(true);
            return pageRef;
    }
   
   
    
 public PageReference doCancel(){
         
         PageReference pageRef = new PageReference('/');
            pageRef.setRedirect(true);
            return pageRef;
    }


 public class wrapAgent{
    public User teleAgent {get; set;}//Please put the custom metadata names
    public Boolean selected {get; set;}


    //This is the contructor method. When we create a new object we pass a telesales metadata member that is set to the acc property. We also set the selected value to false
    public wrapAgent(User teleSalesAgent) {
        teleAgent = teleSalesAgent;
        selected = false;

    }
}
}
and below is my test class:
@isTest
public class Test_TodayTeleSalesDetails {

    public static testMethod void validateusersinqueue() {
    Group testGroup = new Group(Name='test group', Type='Queue');
	insert testGroup;

	System.runAs(new User(Id=UserInfo.getUserId()))
	{
    QueuesObject testQueue = new QueueSObject(QueueID = testGroup.id, SObjectType = 'Lead');
    insert testQueue;
	}
   	Test.startTest();
     TodayTelesalesDetails telesalesDetails=new TodayTelesalesDetails();
       telesalesDetails.doFullSave();
        telesalesDetails.doCancel();
    Test.stopTest();
}
}

I am not able to cover below lines of code:
for(User us : [select id from User where id =: userSetId])
    {
        system.debug('message6>>'+us);
        for(Group gg : [select id,name from Group where type = 'Queue' and Name = 'TeleSales Queue'])
        {
            GroupMember gm = new GroupMember();
            gm.groupId = gg.id;
            gm.UserOrGroupId = us.Id;
            gmm.add(gm);
        }
        
    }
Below is the screenshot for the same:
Lines of Code is not covering
My current code coverage stands at 73%

Many I request to help me on same to get a code coverage above 75%

Many thanks in advance

Thanks & Regards,
Harjeet
I have a Flow that creates a Case from an Opportunity. I don't want it to return to the Opportunity but rather when the Flow finishes I want to see the Newly Created Case
Hello.  I'm new to salesforce.  How do I create a trigger that will update the lead status to working when an activity is created (event, task, call)?  I saw this code while doing research, and it works for logging a call, but does not update the status if I schedule an event.  Any help will be appreciated.

trigger changeLeadStatus on Task (before insert, before update) {
    String desiredNewLeadStatus = 'Working';

    List<Id> leadIds=new List<Id>();
    for(Task t:trigger.new){
        if(t.Status=='Completed'){
            if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
                leadIds.add(t.whoId);
            }//if 2
        }//if 1
    }//for
    List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
    For (Lead l:leadsToUpdate){
        l.Status=desiredNewLeadStatus;
    }//for
    
    try{
        update leadsToUpdate;
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }
}//trigger
 
Hi All,

I have developed an apex class whcih basically assign users to queue dynamically.I have a VF page which will launch from a custom VF tab.This VF page shows few users and with the checkbox.When checkbox against the username is marked and hit Save button then seleected users will go to the queue defined in class.
Below is my clas:
public class TodayTelesalesDetails {

public Date Today { 
    get { 
        return Date.today(); 
    }
}
public List<wrapAgent> wrapAgentList{get; set;}
public List<User> selectedAgents{get;set;}

public TodayTelesalesDetails (){
   
    if(wrapAgentList == null) {
        wrapAgentList = new List<wrapAgent>();

        for(User teleSalesAgent: [select Id, Name, Email from User where Name IN('Steve Waugh','Yuvraj Singh')]) {
            // As each agent is processed we create a new wrap object and add it to the wrapAgentList
            wrapAgentList.add(new wrapAgent(teleSalesAgent));
    }
}
}

public PageReference doFullSave(){

    set<id> userSetId = new set<id>();
    list<GroupMember> gmm = new list<GroupMember>();
    List<GroupMember> toBeDeleted= [SELECT Id, GroupId, UserOrGroupId FROM GroupMember where GroupId = '00G9D000000toPYUAY'];
    delete toBeDeleted;
    List<User> userlist=[select Id, Name from User where Name IN('Steve Waugh','Yuvraj Singh')];
   
    for(User u : userlist)
    { 
    system.debug('message3>>'+u);
         for(wrapAgent wrapAccountObj : wrapAgentList) {
             
            if(wrapAccountObj.selected == true) {
                userSetId.add(wrapAccountObj.teleAgent.id);
                
            }
        }

    }
      
    for(User us : [select id from User where id =: userSetId])
    {
       
        for(Group gg : [select id,name from Group where type = 'Queue' and Name = 'TeleSales Queue'])
        {
            GroupMember gm = new GroupMember();
            gm.groupId = gg.id;
            gm.UserOrGroupId = us.Id;
            gmm.add(gm);
        }
        
    }
            
     
    insert gmm;
    PageReference pageRef = new PageReference('/');
            pageRef.setRedirect(true);
            return pageRef;
    }
   
   
    
 public PageReference doCancel(){
         
         PageReference pageRef = new PageReference('/');
            pageRef.setRedirect(true);
            return pageRef;
    }


 public class wrapAgent{
    public User teleAgent {get; set;}//Please put the custom metadata names
    public Boolean selected {get; set;}


    //This is the contructor method. When we create a new object we pass a telesales metadata member that is set to the acc property. We also set the selected value to false
    public wrapAgent(User teleSalesAgent) {
        teleAgent = teleSalesAgent;
        selected = false;

    }
}
}
and below is my test class:
@isTest
public class Test_TodayTeleSalesDetails {

    public static testMethod void validateusersinqueue() {
    Group testGroup = new Group(Name='test group', Type='Queue');
	insert testGroup;

	System.runAs(new User(Id=UserInfo.getUserId()))
	{
    QueuesObject testQueue = new QueueSObject(QueueID = testGroup.id, SObjectType = 'Lead');
    insert testQueue;
	}
   	Test.startTest();
     TodayTelesalesDetails telesalesDetails=new TodayTelesalesDetails();
       telesalesDetails.doFullSave();
        telesalesDetails.doCancel();
    Test.stopTest();
}
}

I am not able to cover below lines of code:
for(User us : [select id from User where id =: userSetId])
    {
        system.debug('message6>>'+us);
        for(Group gg : [select id,name from Group where type = 'Queue' and Name = 'TeleSales Queue'])
        {
            GroupMember gm = new GroupMember();
            gm.groupId = gg.id;
            gm.UserOrGroupId = us.Id;
            gmm.add(gm);
        }
        
    }
Below is the screenshot for the same:
Lines of Code is not covering
My current code coverage stands at 73%

Many I request to help me on same to get a code coverage above 75%

Many thanks in advance

Thanks & Regards,
Harjeet