• hamada sayed
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    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

error message goes on, "An account owner must be associated with a role to enable portal users or transfer portal users to his or her account."

 

I'm lost. I'm trying to setup website authenticated user access to a force.com site.  I am the only Enterprise user, all other users are guests or website authenticated.  I assume that I am the account owner, but I can't find the field that I need to change to make this work. I know someone will probably need more info than this to help, but don't know what else to provide. 

 

Please ask away!

 

thank you