The Class Code for the Semaphore used in the KM solution I changed slightly by adding a method calledtrigger AccountAfterUpdate on Account (after update) {
if(checkRecursive.isFirstRun()){ // To avoid the recursion on trigger One Trigger Per Object
Integer acctLimit = Trigger.new.size();
List<Account> UpdateAccountList = new List<Account>();
List<Account> UpdateRegLevelList = new List<Account>();
List<ID> acctIDs = new List<ID>();
List<Account> clonedAccounts = new List<Account>();
Account modifiedAccount;
Account clonedAccount;
List<RecordType> getPersonRecordType = [Select Id from recordType where Name = 'Individual_Person'];
List<RecordType> getUSRecordType = [Select Id from recordType where Name = 'US Organization'];
List<Account> OtherAccounts = new List<Account>(); //non-PMM Account tasks.
//1. See if its PMM value has changed for Account records.
for(Integer aCnt = 0; aCnt < acctLimit; aCnt++){
//A. <<For Address Synchronization:>> // See if Address have been updated for Person Accounts
if(Trigger.new[aCnt].RecordTypeId == getPersonRecordType[0].Id){
if(Trigger.new[aCnt].ShippingStreet != Trigger.old[aCnt].ShippingStreet ||
Trigger.new[aCnt].ShippingCity != Trigger.old[aCnt].ShippingCity ||
Trigger.new[aCnt].ShippingState != Trigger.old[aCnt].ShippingState ||
Trigger.new[aCnt].ShippingCountry != Trigger.old[aCnt].ShippingCountry ||
Trigger.new[aCnt].ShippingPostalCode != Trigger.old[aCnt].ShippingPostalCode ||
Trigger.new[aCnt].BillingStreet != Trigger.old[aCnt].BillingStreet ||
Trigger.new[aCnt].BillingCity != Trigger.old[aCnt].BillingCity ||
Trigger.new[aCnt].BillingState != Trigger.old[aCnt].BillingState ||
Trigger.new[aCnt].BillingCountry != Trigger.old[aCnt].BillingCountry ||
Trigger.new[aCnt].BillingPostalCode != Trigger.old[aCnt].BillingPostalCode
){
modifiedAccount = Trigger.new[aCnt];
clonedAccount = new Account(Id=modifiedAccount.Id, Physical_Street_1__c =modifiedAccount.BillingStreet, Physical_City__c = modifiedAccount.BillingCity,
Physical_Zip__c = modifiedAccount.BillingPostalCode,Physical_State__c = modifiedAccount.BillingState,
PhysicalCountry__c = modifiedAccount.BillingCountry,Mailing_Street_1__c = modifiedAccount.ShippingStreet,
Mailing_City__c = modifiedAccount.ShippingCity,Mailing_State_Province__c = modifiedAccount.ShippingState,
Mailing_Zip_Postal_Code__c = modifiedAccount.ShippingPostalCode,Mailing_Country__c = modifiedAccount.ShippingCountry);
clonedAccounts.add(clonedAccount);
}
}
//B.<<For Team Member Manager:>> Check to see if the Owner Id has changed on US Organizations
if(Trigger.new[aCnt].RecordTypeId == getUSRecordType[0].Id){ //11-23-2014 Added conditional using Record Type as a flag to process for US Orgs only.
if(Trigger.new[aCnt].OwnerId != Trigger.old[aCnt].OwnerId && (Trigger.new[aCnt].OwnerId != null && Trigger.old[aCnt].OwnerId != null) ){ // This should never happen for Person Accounts.
UpdateAccountList.add(Trigger.new[aCnt]);
acctIDs.add(Trigger.new[aCnt].Id);
}//IF
}//IF
}// FOR
//2. <<For Team Member Manager:>> Displatch for processing which accounts ..
if(UpdateAccountList.size() > 0){
system.debug('<<TMACCTS>> '+UpdateAccountList);
TeamMemberAccounts.handler(UpdateAccountList,acctIDs);
}
//3. <<For Address Synchronization on Person Accounts:>>
if(clonedAccounts.size() > 0 ){
update clonedAccounts;
system.debug('*** New ACCOUNT ID *** '+clonedAccounts[0].Id+' *** New ACCOUNT Mailingn Address *** '+clonedAccounts[0].Mailing_Street_1__c+' *** New ACCOUNT PhysicalAddress *** '+clonedAccounts[0].Physical_Street_1__c);
}
}// checkRecursion
// Before leaving, give 'key' to the next available trigger to unlock critical section for Access.
checkRecursive.isResetRun(); // <------------ KB Class Update. Free up the firstRun'key' .
}
isResetRun:
Thanks for your help, comments, and questions. I just want to make sure that either I fixed the KB or if I have accidentally created any additional problems for myself . Again, with my solution the 4 trigger processes only fire once after a contact has been updated.public class checkRecursive{
private static boolean firstRun = true;
public static boolean isFirstRun(){
if(firstRun){
firstRun = false;
return true;
}else{
return firstRun;
}
}
public static boolean isResetRun(){ // <------------ New method to free up the 'key' firstRun
firstRun = true;
return true;
}
}// checkRecursive
karanraj,
OK I will test your solution to make sure but I thought that when I removed the reset that no other triggers ran which means that I only have the Registration trigger running but the AccountGeoCodeAfterUpdate will not run at all. (I saw this happn within the log file.)