• Nishant Sunadham
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi!
I'm trying to figure out how to write a test class for this trigger. Any help/ideas would be appreciated :)

trigger TR_UpdateCaseOwners on Case (before insert) {
    
    //Variable declarations
    List <Id> AccountIds = new List <Id>();
    List <Programs__C> ProgramOwner = new List<Programs__C>();
    List <Contact> contacts = new List<Contact>();
    List <User> OwnerID = new list<User>();
    
     for (Case c :Trigger.new) {
        if (c.type == 'Program Inquiry') {
           
      Set<Contact> con = new set<Contact>([Select Intent__C, CSU_Primary_Degree_Interest__c, CSU_Primary_Certificate_Interest__c FROM CONTACT WHERE ID = : c.ContactId]);
        
      for (Contact B : con){
      
      if (B.Intent__C == 'Degree') {
      
    //Update case owner
    ProgramOwner = ([SELECT ProgramOwner__c from Programs__C WHERE NAME =: B.CSU_Primary_Degree_Interest__c]);         
    
    //ProgramOwner SObject
    for (Programs__C P : ProgramOwner){
    
    //Query user table for program owner GUID    
    OwnerID = ([Select ID FROM User WHERE Name =: P.ProgramOwner__c]);    
    
    for (User U : OwnerID){
    
    //Assign new ID    
    C.OwnerID = U.ID; 
    
    }     
   }      
 }
    
 else  {
    
    if (B.Intent__C == 'Certificate')
    {
    
   //Update case owner
    ProgramOwner = ([SELECT ProgramOwner__c from Programs__C WHERE NAME =: B.CSU_Primary_Degree_Interest__c]);         
    
    //ProgramOwner SObject
    for (Programs__C P : ProgramOwner){
    
    //Query user table for program owner GUID    
    OwnerID = ([Select ID FROM User WHERE Name =: P.ProgramOwner__c]);    
    
    for (User U : OwnerID){
    
    //Assign new ID    
    C.OwnerID = U.ID; 
    
}     
}      
}
}
}
}
}
}