+ Start a Discussion

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) {
        for(User uids:Trigger.new){
               id userId = uids.id;


My Apex Class:::::::::::::::::::::
global class AsyncApex {
      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
yes it working right