I have tried to search up on this for a while now but couldn't find any answer to my question... I have wrote a simple trigger that when an Account record is moved out of view (Moved out of view = true), then all the contacts associated with that specific account will be automatically marked as moved out of view (Moved out of view = true). Trigger works in sandbox and also before this incident, I was able to deploy this into production, but now as I was trying to add onto the same existing test class, I have noticed through System.assertEquals() that the trigger is not firing... Can someone please help explain what's going on? Thanks in advance...
Trigger:
trigger moveContactsOutOfView on Account (After Update) {
if(checkRecursive.runOnce()){
set<String> notAccId = New Set<String>();
set<String> accId = New Set<string>();
List<Contact> conUpdate = new List<Contact>();
List<Contact> con1Update = new list<Contact>();
List<AccountTeamMember> d1 = new List<AccountTeamMember>();
for (Account a1: trigger.new){
if (a1.ID != null && a1.Move_out_of_view__c == True){
accId.Add(a1.ID);
}
else {
notAccId.add(a1.ID);
}
}
LIST<Contact> cY = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: AccId];
LIST<Contact> cN = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: notAccId];
List<AccountTeamMember> toBeDeleted =[SELECT ID, LastModifiedById FROM AccountTeamMember WHERE AccountID In: AccId];
for (Account a1: trigger.new){
for (Contact c1:cY){
if (c1.LastModifiedById != '00500000006xdMm' && c1.LastModifiedById != '00500000006wnoE' && c1.LastModifiedById != '00500000006wsIm'){
c1.Move_out_of_view__c = True;
conUpdate.add(c1);
}
}
for (Contact c2:cN){
if (c2.LastModifiedById != '00500000006xdMm'&& c2.LastModifiedById != '00500000006wnoE' && c2.LastModifiedById != '00500000006wsIm'){
c2.Move_out_of_view__c = False;
con1Update.add(c2);
}
}
}
for (AccountTeamMember t1:toBeDeleted){
if (t1.LastModifiedById != '00500000006xdMm' && t1.LastModifiedById != '00500000006wnoE' && t1.LastModifiedById != '00500000006wsIm'){
d1.add(t1);
}
}
update conUpdate;
update con1Update;
delete d1;
}
}
test class:
@isTest
public class TestPrimaryLiaisonCount2{
static testMethod void insertNewContact(){
//NEW Account record
Account ACC = new Account();
ACC.recordtypeID = '012000000000j8S';
ACC.Name = 'Liu Inc';
ACC.Industry = 'Advertising';
ACC.NumberOfEmployees = 500;
ACC.Center__c = 'Full Service';
ACC.Move_out_of_view__c = False;
insert ACC;
string accId = ACC.id;
//NEW Contact record for 'ACC'
Contact ACDC = new Contact();
ACDC.FirstName = 'Testing';
ACDC.LastName = 'DEV';
ACDC.Primary_Liaison__c = 'Center';
ACDC.AccountID = ACC.Id;
insert ACDC;
ACDC = [SELECT Id, AccountID, Move_out_of_view__c FROM Contact WHERE AccountID =: accId limit 1];
system.assertEquals(false, ACDC.Move_out_of_view__c);
ACC.Move_out_of_view__c = True;
update ACC;
ACDC = [SELECT Id, AccountID, Move_out_of_view__c FROM Contact WHERE AccountID =: accId limit 1];
system.assertEquals(true, ACDC.Move_out_of_view__c);
}
}
UPDATE - checkRecursive class:
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}else{
return run;
}
}
}