Tuesday, 12 March 2019

CNCAssinment_lead

*********Scenario___1*****

/****************************************************************************************
    Class Name:RSAG_LeadTrigger_Helper
    Developer Name:Krishna Nagendra Rao.Yerru         
    Created Date:   11-Mar-2019
    Test Class Name: 
    Project Name: SP-3849-CFI SCS Legacy Referral Bank Leads - Lead trigger changes for lead assignment functionality               
******************************************************************************************
Change History
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
ChangeVersion       Name                  Date              Task/Case#                              Description
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

******************************************************************************************/
public class RSAG_LeadTrigger_Helper{
    
      public static void CFILeadAssignment(List<Lead> NewListLeads){
              system.debug('@@CFILeadAssignment.'); 
        Map<Lead, String> CFI_LeadAssin_Map = new Map<Lead, String>();            
            for(Lead l:NewListLeads){
                system.debug('@@Lead is***'+l);
                String OwnrID=l.OwnerID;            
                system.debug('@@Owner is ***'+l.OwnerID);       
                if(l.OwnerID !=null){
                     if (!OwnrID.startsWith('00G')){
                        system.debug('@@OwnerID  id ***'+l.Owner);                                                                             
                        CFI_LeadAssin_Map.put(l,OwnrID);                    
                    }
                }
            }
            if(CFI_LeadAssin_Map.Size()>0){
                OwnerAssignment2(CFI_LeadAssin_Map);
            }
      }
      
      public Static Void OwnerAssignment2(Map<Lead, String> CFILeadAssinMap) {
          QueueSobject qus = [Select Id,Queue.id,Queue.Name from QueueSobject q where q.Queue.Name ='CFI_LeadAssignment_Queue' and q.SobjectType='Lead'];
           for(User Userdata:[Select Id,FirstName,LastName,Name,ManagerID,Manager.isActive,IsActive from User where Id =:CFILeadAssinMap.Values()]){
               for(Lead le:CFILeadAssinMap.Keyset()){
                   if(le.OwnerID==Userdata.id){
                       //Start Assignining
                        if(Userdata.IsActive==false){
                            if(Userdata.ManagerID==null){
                                le.OwnerID=qus.Queue.id;
                            }
                            else if(Userdata.ManagerID!=null){
                                String mgrid=Userdata.ManagerID;
                                boolean mgrdata=Userdata.Manager.isActive;
                                system.debug('@@mgr status is***'+mgrdata);                                                
                                if(mgrdata==true){ 
                                    le.OwnerID=mgrid;                           
                                }else if(!mgrdata){
                                    le.OwnerID=qus.Queue.id;
                                }

                            }
                        }
                       //END Assigning
                   }                           
               }
            }              
      }
      
       public Static String OwnerAssignment(String OwnrID) {
           String AssignedIDis=OwnrID;
            QueueSobject qus = [Select Id,Queue.id,Queue.Name from QueueSobject q where q.Queue.Name ='CFI_LeadAssignment_Queue' and q.SobjectType='Lead'];
           User Userdata=[Select Id,FirstName,LastName,Name,ManagerID,Manager.isActive,IsActive from User where Id =:OwnrID limit 1];
           if(Userdata!=null){
               if(Userdata.IsActive==false){
                   if(Userdata.ManagerID==null){
                      AssignedIDis=qus.Queue.id;
                   }
                   else if(Userdata.ManagerID!=null){
                       String mgrid=Userdata.ManagerID;
                        boolean mgrdata=Userdata.Manager.isActive;
                        system.debug('@@mgr status is***'+mgrdata);                                                
                            if(mgrdata==true){ 
                                AssignedIDis=mgrid;                         
                            }else if(!mgrdata){
                                AssignedIDis=qus.Queue.id;
                            }
                       
                   }
            }  
           }
          System.debug('AssignedIDis **'+AssignedIDis);
         return AssignedIDis;  
       }
    
}


*****************Scenario---2****

/****************************************************************************************
    Class Name:RSAG_LeadTrigger_Helper
    Developer Name:Krishna Nagendra Rao.Yerru       
    Created Date:   11-Mar-2019
    Test Class Name:
    Project Name: SP-3849-CFI SCS Legacy Referral Bank Leads - Lead trigger changes for lead assignment functionality             
******************************************************************************************
Change History
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
ChangeVersion       Name                  Date              Task/Case#                              Description
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

******************************************************************************************/
public class RSAG_LeadTrigger_Helper{
   
      public static void CFILeadAssignment(List<Lead> NewListLeads){
              system.debug('@@CFILeadAssignment.');         
            for(Lead l:NewListLeads){
                system.debug('@@Lead is***'+l);
                String OwnrID=l.OwnerID;           
                system.debug('@@Owner is ***'+l.OwnerID);     
                if(l.OwnerID !=null){
                     if (!OwnrID.startsWith('00G')){
                        system.debug('@@OwnerID  id ***'+l.Owner);                                                     
                        String assignedID=OwnerAssignment(OwnrID);                     
                        l.OwnerID=assignedID; 
                    }
                }
            }
      }
     
       public Static String OwnerAssignment(String OwnrID) {
           String AssignedIDis=OwnrID;
            QueueSobject qus = [Select Id,Queue.id,Queue.Name from QueueSobject q where q.Queue.Name ='CFI_LeadAssignment_Queue' and q.SobjectType='Lead'];
           User Userdata=[Select Id,FirstName,LastName,Name,ManagerID,Manager.isActive,IsActive from User where Id =:OwnrID limit 1];
           if(Userdata!=null){
               if(Userdata.IsActive==false){
                   if(Userdata.ManagerID==null){
                      AssignedIDis=qus.Queue.id;
                   }
                   else if(Userdata.ManagerID!=null){
                       String mgrid=Userdata.ManagerID;
                        boolean mgrdata=Userdata.Manager.isActive;
system.debug('@@mgr status is***'+mgrdata);                                               
                            if(mgrdata==true){
AssignedIDis=mgrid;
                            }else if(!mgrdata){
                                AssignedIDis=qus.Queue.id;
                            }
                     
                   }
            } 
           }
          System.debug('AssignedIDis **'+AssignedIDis);
         return AssignedIDis; 
       }
   
}

No comments:

Post a Comment