You need to sign in to do that
Don't have an account?
Nishant Sunadham
Test class needed for this Trigger
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;
}
}
}
}
}
}
}
}
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;
}
}
}
}
}
}
}
}
Hi Nishant,
Here is the test class.
I hope this solves your problem.
Please mark as best answer if this helps you.
Thanks
Deepak