+ Start a Discussion
NNRNNR 

Test Class for Below Trigger and @future method

Hi frnds I am New to write Test class plz help me out...........
My trigger ::::::::::::::::::::::::::::::::::;

trigger AddChatterGroup on User (after insert) {
    if(Trigger.Isinsert){
        for(User uids:Trigger.new){
           if(uids.nnr__c=='knr'){
               id userId = uids.id;
           asyncApex.addUserToGroup(userId);

           }
        }
  }     
}

My Apex Class:::::::::::::::::::::
global class AsyncApex {
      @future
      public static void AddUserToGroup(id userId ) {
          try {
              List<CollaborationGroupMember> CG= new List<CollaborationGroupMember>();                     
              Id cgID = [ Select Id
                          FROM CollaborationGroup
                          WHERE Name ='Nnrgroup' LIMIT 1 ].ID;
             CG.add(new CollaborationGroupMember (CollaborationGroupId = cgID, MemberId = userId));  
             insert CG;
          } catch (QueryException qe) {
              System.debug('QueryException in AsyncApex.AddUserToGroup is :' + qe);
          } catch (Exception ex) {
              System.debug('Exception in AsyncApex.AddUserToGroup is :' + ex);
          }   
      }
  }
 
Gaurav NirwalGaurav Nirwal
Please tell me that the trigger can works and your requirements for write a trigger
NNRNNR
yes it working right