function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Unexpected triggers being fired within my system

Hi there,

We released our system about 3 weeks ago and everything has gone quite smoothly. however every now and again something completely random will happen, mainly on the account_status__c object, this is set to change when certain things happen in the system. 

This works, however randomly a whole bunch of account_status__c records will jsut be updated and there is no reason why. What can be causing this?

Thank you for your time.
Best Answer chosen by Developer.mikie.Apex.Student
chris_centrachris_centra
Hello.  You say random - is there any action that reliably causes it to happen?  Presumably there is either a workflow or trigger firing - which may be causing other workflows/triggers to fire, which could be causing these unexpected results.  (Have you tried adding debug code and watching the logs so that you can see what is happening?)

All Answers

chris_centrachris_centra
Hello.  You say random - is there any action that reliably causes it to happen?  Presumably there is either a workflow or trigger firing - which may be causing other workflows/triggers to fire, which could be causing these unexpected results.  (Have you tried adding debug code and watching the logs so that you can see what is happening?)
This was selected as the best answer
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
It seems to happen randomly. I have an idea what triggers are probably causing it, as they are the only ones that would update the status as such. However, it does not make sense they are triggering based on the criteria needed to trigger them.

These are my two triggers:

 
rigger ServiceTrigger on Service__c (before update,before insert, before delete, after update, after insert, after delete) {

//Query required lists and values and maps
//GrabReference Trigger
List<Destiny_Products_and_Services__c> dpas =  [Select Id, Service_name__c, Service_type__c from Destiny_Products_and_Services__c]; 

//ClientPath trigger
List<Account_Status__c> AccSt = new List<Account_Status__c>();
List<Service__c> ServList = new List<Service__c>();
List<Account_Status__c> updatedAccSt = new List<Account_Status__c>();
List<Id> accIds = new List<Id>(); 

//Service Validation
Map<Id, Destiny_Products_and_Services__c> mapServiceRules = new Map<Id, Destiny_Products_and_Services__c>();
mapServiceRules.putAll([SELECT Id, Name, MaximumRecords__c FROM Destiny_Products_and_Services__c]); //we're using the ID as the key now

Map<Id, Service__c> mapServiceContinued = new Map<Id, Service__c>();
Set<Id> setAccountIds = new Set<Id>();

     
if(trigger.isbefore){
if(trigger.isinsert){
//before insert logic
//Service_GrabReference
for (Service__c  dp: trigger.new) {
    for(Destiny_Products_and_Services__c D:dpas ){
       if(dp.Service_Name__c != null && dp.Service_type__c != null) {

              if (dpas.size() > 0){
              
if(dp.Service_name__c == D.Service_name__c  && dp.Service_Type__c == D.Service_Type__c)
            dp.Destiny_Service__c = D.Id;
              }         
       }
    }
}
//Service_Grabreference

//ClientPath_Service Before insert
for (Service__c Ser: trigger.new) {
       if(Ser.Account__c != null) {
       accIds.add(Ser.Account__c);
      
       }
       }
  AccSt = [Select Id,Account_Status__c from Account_Status__c WHERE Account__c in :accIds];
  ServList = [Select Id, Service_Stage__c, Service_Name__c, Service_type__c, Support_Continued_Service__c from Service__c WHERE Account__c in :accIds];
  mapServiceContinued.putAll(ServList);
  for(Account_Status__c a : AccSt)
  {
  
  
  if(ServList.size()<1){
   //First Service added status set
       a.Account_Status__c = 'New Service Added: Awaiting Payment';
       a.First_Service__c = date.today();
}       
       
       
for (Service__c Ser: trigger.new) {

/////////////////////////////////SERVICE CONTINUED\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

if(Ser.Service_Stage__c == 'Essential Property Education Only (Upgrade)' || Ser.Service_Stage__c == 'Intensive Property Coaching (Support Continued)' || Ser.Service_Stage__c == 'Momentum Support (Support Continued)' || Ser.Service_Stage__c == 'Advantage Program (Support Continued)') {
If(Ser.Support_Continued_Service__c != null){
if(mapServiceContinued.containsKey(Ser.Support_Continued_Service__c)){

//Setting status based on new service.
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Essential Property Education Only' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Essential Property Education Only (Start)') {
       a.Account_Status__c = 'EPE Course Only';
       a.EPE_Course_Only__c = date.today();
    }   
//Service End: Advantage
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Advantage Program' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Advantage Program (Start)') {
       a.Account_Status__c = 'Advantage';
       a.Advantage__c = date.today();

    }
//Service End: IPC
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Intensive Property Coaching' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Intensive Property Coaching (Start)') {
       a.Account_Status__c = 'Intensive Property Coaching';
       a.IPC__C = date.today();
    }
//Service End: Momentum Plus    
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Momentum Support' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Momentum Support (Start)' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Plus') {
       a.Account_Status__c = 'Momentum Plus';
       a.Support_Momentum_Plus__c = date.today();
    }
//Service End: Momentum Standard    
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Momentum Support' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Momentum Support (Start)'  && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Standard' || mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Referee-Free' || mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Referer-Free' || mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Complimentary') {
       a.Account_Status__c = 'Momentum';
       a.Support_Momentum__c = date.today();
    }
//Service End: Momentum Free    
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Momentum Support' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Momentum Support (Start)'  && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Plus-Fin-Free' ) {
       a.Account_Status__c = 'Momentum Free';
       a.Momentum_Free__c = date.today();
    }
    
 }  
}
}
/////////////////////////////////SERVICE CONTINUED\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////////////SERVICE END\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if(Ser.Service_Name__c== 'Essential Property Education Only' && Ser.Service_Stage__c == 'Essential Property Education Only (End)') {
       a.Account_Status__c = 'Former EPE Only';
       a.Former_EPE_Only__c= date.today();
    }   
//Service End: Advantage
if(Ser.Service_Name__c== 'Advantage Program' && Ser.Service_Stage__c == 'Advantage Program (End)') {
       a.Account_Status__c = 'Former Advantage';
       a.Former_Advantage__c = date.today();

    }
//Service End: IPC
if(Ser.Service_Name__c== 'Intensive Property Coaching' && Ser.Service_Stage__c == 'Intensive Property Coaching (End)') {
       a.Account_Status__c = 'Former IPC';
       a.Former_IPC__c = date.today();
    }
//Service End: Momentum Plus    
if(Ser.Service_Name__c== 'Momentum Support' && Ser.Service_Stage__c == 'Momentum Support (End)' && Ser.Service_type__c == 'Plus') {
       a.Account_Status__c = 'Former Momentum Plus';
       a.Former_Momentum_Plus__c = date.today();
    }
//Service End: Momentum Standard    
if(Ser.Service_Name__c== 'Momentum Support' && Ser.Service_Stage__c == 'Momentum Support (End)'  && (Ser.Service_type__c == 'Standard' || Ser.Service_type__c == 'Referee-Free' || Ser.Service_type__c == 'Referer-Free' || Ser.Service_type__c == 'Complimentary')) {
       a.Account_Status__c = 'Former Momentum';
       a.Former_Momentum__c = date.today();
    }
//Service End: Momentum Free    
if(Ser.Service_Name__c== 'Momentum Support' && Ser.Service_Stage__c == 'Momentum Support (End)'  && Ser.Service_type__c == 'Plus-Fin-Free' ) {
       a.Account_Status__c = 'Former Momentum Free';
       a.Former_Momentum__c = date.today();
    }
//Service End: PAS        
//if(Ser.Service_Name__c== 'Property Acquisition Support' && Ser.Service_Stage__c == 'Property Acquisition Support (End)') {
//     a.Account_Status__c = 'Former PAS';
//     a.Former_PAS__c = date.today();
//   }  
 /////////////////////////////////////SERVICE END\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
       
}       
       updatedAccSt.add(a);
}


if(updatedAccSt.size()>0)
{
update updatedAccSt;
}
//ClientPath_Service Before insert

//ServiceValidation
 for(Service__c objService : trigger.new) {
    setAccountIds.add(objService.Account__c);
  }
  
  //Populate a map of the aggregate query results
  Map<String, Map<String, Decimal>> mapResults = new Map<String, Map<String, Decimal>>();
  AggregateResult[] groupedResult = [SELECT Account__c, Destiny_Service__c, Count(Id) countOfRecords
                                     FROM Service__c
                                     WHERE Account__c IN :setAccountIds
                                     GROUP BY Account__c, Destiny_Service__c];

  for(AggregateResult ar : groupedResult) {
    if(!mapResults.containsKey((String)ar.get('Account__c'))) {
      mapResults.put((String)ar.get('Account__c'), new Map<String, Decimal>());
    }
    mapResults.get((String)ar.get('Account__c')).put((String)ar.get('Destiny_Service__c'), (Decimal)ar.get('countOfRecords'));
  }

  //Iterate through your list of Service__c records and generate an error for any 
  //that have a matching Account__c in the map
  for(Service__c objService : trigger.new) {
    if(mapServiceRules.containsKey(objService.Destiny_Service__c) && mapServiceRules.get(objService.Destiny_Service__c).MaximumRecords__c != null) {    //If there is no rule set ignore the record
      if(mapResults.containsKey(objService.Account__c)) {
        if(mapResults.get(objService.Account__c).containsKey(objService.Destiny_Service__c)) {
          if(mapResults.get(objService.Account__c).get(objService.Destiny_Service__c) >= mapServiceRules.get(objService.Destiny_Service__c).MaximumRecords__c) {
            objService.addError('This service has already been added the maximum number of times');
          }
        }
      }
    }
  }
//ServiceValidation


}
else if(trigger.isupdate){
//before update logic
//Service_GrabReference Before update
for (Service__c  dp: trigger.new) {
    for(Destiny_Products_and_Services__c D:dpas ){
       if(dp.Service_Name__c != null && dp.Service_type__c != null) {

              if (dpas.size() > 0){
              
if(dp.Service_name__c == D.Service_name__c  && dp.Service_Type__c == D.Service_Type__c)
            dp.Destiny_Service__c = D.Id;
              }         
       }
    }
}
//Service_Grabreference Before update

//ClientPath_Service Before Update
for (Service__c Ser: trigger.new) {
       if(Ser.Account__c != null) {
       accIds.add(Ser.Account__c);
      
       }
       }
  AccSt = [Select Id,Account_Status__c from Account_Status__c WHERE Account__c in :accIds];
  ServList = [Select Id, Service_Stage__c, Service_type__c, Support_Continued_Service__c, Service_Name__c   from Service__c WHERE Account__c in :accIds];
   mapServiceContinued.putAll(ServList);
  for(Account_Status__c a : AccSt)
  {
  
  
  if(ServList.size()<1){
   //First Service added status set
       a.Account_Status__c = 'New Service Added: Awaiting Payment';
       a.First_Service__c = date.today();
}       
       
       
for (Service__c Ser: trigger.new) {

/////////////////////////////////SERVICE CONTINUED\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

if(Ser.Service_Stage__c == 'Essential Property Education Only (Upgrade)' || Ser.Service_Stage__c == 'Intensive Property Coaching (Support Continued)' || Ser.Service_Stage__c == 'Momentum Support (Support Continued)' || Ser.Service_Stage__c == 'Advantage Program (Support Continued)') {
If(Ser.Support_Continued_Service__c != null){
if(mapServiceContinued.containsKey(Ser.Support_Continued_Service__c)){

//Setting status based on new service.
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Essential Property Education Only' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Essential Property Education Only (Start)') {
       a.Account_Status__c = 'EPE Course Only';
       a.EPE_Course_Only__c = date.today();
    }   
//Service End: Advantage
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Advantage Program' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Advantage Program (Start)') {
       a.Account_Status__c = 'Advantage';
       a.Advantage__c = date.today();

    }
//Service End: IPC
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Intensive Property Coaching' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Intensive Property Coaching (Start)') {
       a.Account_Status__c = 'Intensive Property Coaching';
       a.IPC__C = date.today();
    }
//Service End: Momentum Plus    
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Momentum Support' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Momentum Support (Start)' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Plus') {
       a.Account_Status__c = 'Momentum Plus';
       a.Support_Momentum_Plus__c = date.today();
    }
//Service End: Momentum Standard    
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Momentum Support' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Momentum Support (Start)'  && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Standard' || mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Referee-Free' || mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Referer-Free' || mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Complimentary') {
       a.Account_Status__c = 'Momentum';
       a.Support_Momentum__c = date.today();
    }
//Service End: Momentum Free    
if(mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Name__c == 'Momentum Support' && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_Stage__c == 'Momentum Support (Start)'  && mapServiceContinued.get(Ser.Support_Continued_Service__c).Service_type__c == 'Plus-Fin-Free' ) {
       a.Account_Status__c = 'Momentum Free';
       a.Momentum_Free__c = date.today();
    }
    
 }  
}
}
/////////////////////////////////SERVICE CONTINUED\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////////////////////////////SERVICE END\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if(Ser.Service_Name__c== 'Essential Property Education Only' && Ser.Service_Stage__c == 'Essential Property Education Only (End)') {
       a.Account_Status__c = 'Former EPE Only';
       a.Former_EPE_Only__c= date.today();
    }   
//Service End: Advantage
if(Ser.Service_Name__c== 'Advantage Program' && Ser.Service_Stage__c == 'Advantage Program (End)') {
       a.Account_Status__c = 'Former Advantage';
       a.Former_Advantage__c = date.today();

    }
//Service End: IPC
if(Ser.Service_Name__c== 'Intensive Property Coaching' && Ser.Service_Stage__c == 'Intensive Property Coaching (End)') {
       a.Account_Status__c = 'Former IPC';
       a.Former_IPC__c = date.today();
    }
//Service End: Momentum Plus    
if(Ser.Service_Name__c== 'Momentum Support' && Ser.Service_Stage__c == 'Momentum Support (End)' && Ser.Service_type__c == 'Plus') {
       a.Account_Status__c = 'Former Momentum Plus';
       a.Former_Momentum_Plus__c = date.today();
    }
//Service End: Momentum Standard    
if(Ser.Service_Name__c== 'Momentum Support' && Ser.Service_Stage__c == 'Momentum Support (End)'  && (Ser.Service_type__c == 'Standard' || Ser.Service_type__c == 'Referee-Free' || Ser.Service_type__c == 'Referer-Free' || Ser.Service_type__c == 'Complimentary')) {
       a.Account_Status__c = 'Former Momentum';
       a.Former_Momentum__c = date.today();
    }
//Service End: Momentum Free    
if(Ser.Service_Name__c== 'Momentum Support' && Ser.Service_Stage__c == 'Momentum Support (End)'  && Ser.Service_type__c == 'Plus-Fin-Free' ) {
       a.Account_Status__c = 'Former Momentum Free';
       a.Former_Momentum__c = date.today();
    }
//Service End: PAS        
//if(Ser.Service_Name__c== 'Property Acquisition Support' && Ser.Service_Stage__c == 'Property Acquisition Support (End)') {
//     a.Account_Status__c = 'Former PAS';
//     a.Former_PAS__c = date.today();
//   }  
 /////////////////////////////////////SERVICE END\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\  
       


}
updatedAccSt.add(a);
}






if(updatedAccSt.size()>0)
{
update updatedAccSt;
}
//ClientPath_Service Before insert

}
}
else if(trigger.isafter){
if(trigger.isinsert){ 
//after Insert logic

 

} 
}
}

and

 
public class TransactionTriggerHandler {

private boolean m_isExecuting = True;
private integer BatchSize = 0;
private final static boolean ISUPDATE_TRUE = true;
private final static boolean ISUPDATE_FALSE = false;


public TransactionTriggerHandler (boolean isExecuting, integer size)
{
m_isExecuting = isExecuting;
BatchSize = size;
}
public void onBeforeInsert(list<Transaction__c> triggerNew, map<id,Transaction__c> triggerNewMap)
{
List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c, Office__c from Commission_Period__c];
List<Office_Commission__c> officeCommissions = [Select Id, Commission_Period_Start__c, Commission_Period_End__c, Office__c from Office_Commission__c];
//Account Status Change
List<Account_Status__c> AccSt = new List<Account_Status__c>();
List<Account_Status__c> updatedAccSt = new List<Account_Status__c>();
List<Id> accIds = new List<Id>();
set<Id> traserviceIDset = new set<Id>();
List<Id> SerIds = new List<Id>();

//Service Free Activation
List<Service__c> SerList  = new List<Service__c>();
List<Service__c> SerCountList  = new List<Service__c>();
List<Service__c> UpdatedSer = new List<Service__c>();




for (Transaction__c Tra : triggerNew)
If(Tra.Destiny_Service_No__c != null){
//Account Status Set
traserviceIDset.add(Tra.Destiny_Service_No__c);
//Validation transaction_zero_payment
//If(Tra.amount__c == 0 && Tra.Transaction_Type__c == First Paymment){
//SerIds.add(Tra.Destiny_Service_No__c);
//}
}


for (Transaction__c Tra: triggerNew) {
if(Tra.Account__c != null && (Tra.Transaction_Type__c == 'First Payment'||Tra.Transaction_Type__c == 'Refund')) {
accIds.add(Tra.Account__c);
}
if(Tra.Destiny_Service_No__c!= null){
SerIds.add(Tra.Destiny_Service_No__c);

}
}



//Account Status Map
map<id, service__c> servicesMap = new Map<id, Service__c>([Select id, Service_Name__c, service_type__c, Free_Service_Activated__c from Service__c where id in :traserviceIDset ]);
SerList = [Select Id,Free_Service_Activated__c, First_Payment_Date__c  from Service__c WHERE id in :SerIds];




For(Service__c Ser: SerList ){

for (Transaction__c Tra: triggerNew) {
if(Ser.First_Payment_Date__C == null && Tra.Transaction_Type__c == 'First Payment') {
Ser.First_Payment_Date__C = tra.date_of_payment__c;
}
If(Tra.Transaction_Type__c == 'First Payment' && Tra.Amount__c == 0){

if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Complimentary' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Referee-Free' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Referer-Free' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Plus-Fin-Free' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Plus' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Existing Service @ R1' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Standard') {
Ser.Free_Service_Activated__c = true;

}Else if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Complimentary' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Referee-Free' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Referer-Free' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Plus-Fin-Free' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Plus' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Existing Service @ R1' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c != 'Standard') {
Tra.addError('A transaction amount cannot equal $0 unless it is a transaction which is joined and therefore activating a free, complimentary service or the First Payment of Momentum.');
}
}
}
UpdatedSer.add(Ser);
}






AccSt = [Select Id,Account_Status__c from Account_Status__c WHERE Account__c in :accIds];
SerCountList = [Select Id from Service__c WHERE Account__c in :accIds];

for(Account_Status__c a : AccSt)
{



for (Transaction__c Tra: triggerNew ) {
if(SerCountList.size()<=1){

//First Payment Services
//EPE Only
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Essential Property Education Only' &&  (servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Additional Same Account'||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Complimentary' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'EPE Redo' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'IPC Additional' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'New Client' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'New Partner' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Platinum Client') && Tra.Transaction_Type__c == 'First Payment') {
a.Account_Status__c = 'EPE Course Only';
a.EPE_Course_Only__c = date.today();
}
//Adv New Client
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Advantage Program' && servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Discontinued' && Tra.Transaction_Type__c == 'First Payment') {
a.Account_Status__c = 'Advantage';
a.EPE_Course_Advantage__c = date.today();
}

//IPC New Client
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Intensive Property Coaching' && Tra.Transaction_Type__c == 'First Payment' && (servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Complimentary'||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'New Client' || servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'New Service)')) {
a.Account_Status__c = 'Intensive Property Coaching';
a.EPE_Course_IPC__c = date.today();
}
//IPC Upgrade from EPE
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Intensive Property Coaching' && Tra.Transaction_Type__c == 'First Payment' && servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'IPC Upgrade EPE') {
a.Account_Status__c = 'IPC (Upgrade EPE)';

}
//Momentum Support Standard
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Momentum Support' && Tra.Transaction_Type__c == 'First Payment' && (servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Complimentary'||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Standard' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Referee-Free' ||servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Referer-Free')) {
a.Account_Status__c = 'Momentum';
a.Support_Momentum__c = date.today();
}
//Momentum Support Plus
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Momentum Support' && Tra.Transaction_Type__c == 'First Payment' && servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Plus') {
a.Account_Status__c = 'Momentum Plus';
a.Support_Momentum_Plus__c = date.today();
}
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Momentum Support' && Tra.Transaction_Type__c == 'First Payment' && servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Plus--Fin-Free') {
a.Account_Status__c = 'Momentum Free';
a.Momentum_Free__c = date.today();
}
}



//Refund Services
//EPE Only Refund
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Essential Property Education Only' && Tra.Transaction_Type__c == 'Refund') {
a.Account_Status__c = 'Refund EPE Only';
a.Refund_EPE_Only__c = date.today();
}
//Adv Refund
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Advantage Program' && Tra.Transaction_Type__c == 'Refund') {
a.Account_Status__c = 'Refund Advantage';
a.Refund_Advantage__c = date.today();


}
//IPC Refund
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Intensive Property Coaching' && Tra.Transaction_Type__c == 'Refund') {
a.Account_Status__c = 'Refund IPC';
a.Refund_IPC__c = date.today();
}

//Refund Momentum Support Standard
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Momentum Support' && Tra.Transaction_Type__c == 'Refund' && servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Standard') {
a.Account_Status__c = 'Refund Momentum';
a.Refund_Momentum__c = date.today();
}
//Refund Momentum Support Plus
if(servicesMap.get(Tra.Destiny_Service_No__c).Service_Name__c == 'Momentum Support' && Tra.Transaction_Type__c == 'Refund' && servicesMap.get(Tra.Destiny_Service_No__c).Service_Type__c == 'Plus') {
a.Account_Status__c = 'Refund Momentum Plus';
a.Refund_Momentum_Plus__c= date.today();
}
}
updatedAccSt.add(a);
}



if(updatedAccSt.size()>0)
{
update updatedAccSt;
}
if(UpdatedSer.size()>0)
{
update UpdatedSer;
}





}

public void OnAfterInsert(list<Transaction__c> triggerNew, map<id,Transaction__c> triggerNewMap)
{

//Tra Invoice
set<Id> SerTransactionIDset = new set<Id>();
List<Id> ServIds = new List<Id>();
List<Id> ServIds2 = new List<Id>(); //remove from 176 too if doesnt work
List <Office_Invoice__c> OffInvList = new List <Office_Invoice__c> ();
List <Office_Invoice__c> OffInvList2 = new List <Office_Invoice__c> ();
List <Office_Invoice__c> OffInvListDel = new List <Office_Invoice__c> ();
String ServiceNo;
Decimal InvoiceAmount;
Id TraId;
//TraInvoice

//TraInvoice Trigger Code
for (Transaction__c Tra : triggerNew){
if(Tra.Destiny_Service_No__c != null && Tra.Account__c != null && Tra.Office__c != null){
ServIds2.add(Tra.Destiny_Service_No__c);
}
}
map<id, service__c> SerTranMap = new Map<id, Service__c>([Select id, payment_choice__c, Upfront_Price__c, Ezidebit_Price__c from Service__c where id in :ServIds2]);
for (Transaction__c Tra: triggerNew) {
if(Tra.Destiny_Service_No__c != null && Tra.Account__c != null && Tra.Office__c != null){
 if((SerTranMap.get(Tra.Destiny_Service_No__c).Payment_Choice__c == 'EziDebit Price') && tra.Method__c == 'EZIDEBIT' && Tra.Transaction_Type__c == 'First Payment' ) {
 if(SerTranMap.get(Tra.Destiny_Service_No__c).Ezidebit_Price__c > 0 && SerTranMap.get(Tra.Destiny_Service_No__c).Upfront_Price__c> 0 ){
        Office_Invoice__c OffInv = new Office_Invoice__c(); //instantiate the object to put values for future record
         InvoiceAmount = ((SerTranMap.get(Tra.Destiny_Service_No__c).Ezidebit_Price__c) - (SerTranMap.get(Tra.Destiny_Service_No__c).Upfront_Price__c));
        OffInv.Office_Invoice_amount__c = InvoiceAmount; 
        OffInv.Office_Invoice_amount__c = InvoiceAmount;
        OffInv.Office_name__c = tra.office__c; 
        OffInv.office_invoice_date__c = date.today();
        OffInv.Office_Invoice_type__c = 'EziDebit';
        ServiceNo = string.valueof(SerTranMap.get(Tra.Destiny_Service_No__c).id);     
        ServiceNo = 'Service Ref# - '+ServiceNo;  
        OffInv.Office_Invoice_Description__c = ServiceNo;
        OffInv.EziDebit_Transaction_Reference__c = tra.id;
        OffInvList.add(OffInv);
}
}
}
}

    try {
    
   if(OffInvList.size()>0){ 
    
        insert OffInvList; 
        }  
    } catch (system.Dmlexception e) {
        system.debug (e);
    }




}

public void OnBeforeUpdate(list<Transaction__c> triggerNew, map<id,Transaction__c> triggerNewMap, map<id,Transaction__c> triggerOldMap)
{
//CallBeforeUpdateMethod1formHere();
//CallBeforeUpdateMethod2formHere();



}

public void OnAfterUpdate(list<Transaction__c> triggerNew, map<id,Transaction__c> triggerNewMap, map<id,Transaction__c> triggerOldMap)
{
//CallAfterUpdateMethod1formHere();
//CallAfterUpdateMethod2formHere();
}


}

 
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

The random updates only seem to be...

 

Momentum and Former IPC.