+ Start a Discussion
BenBurbridge(JP)BenBurbridge(JP) 

Auto Creation of Custom Object with Trigger

Hi,

I appreciate lots of similar questions have been asked but I can not workout where the issue is in this code, I have picked this up from a previous employee and am learning.  I have noted the error below as well as bold and underline the line.

I am trying to have a new Accounts Receiveable object create when Work Injury is chosen in a picklist on the Treatment Plan.

Error: Compile Error: Try block must have at least one catch or finally at line 2 column 1

trigger OnceARc on Treatment_Plan__c (after update, after insert) {
try{
if(Test.isRunningTest()||!OnceARc.hasAlreadyRound()){

    list<Accounts_Receivable__c> lst = new list<Accounts_Receivable__c>();
  for(Treatment_Plan__c p:trigger.new){
    boolean nst = false;
    if(trigger.isInsert){
      if(p.Division__c=='Work Injury'){
        nst=true;
      }
    }else if(trigger.isUpdate){
      string ott=trigger.oldmap.get(p.id).Division__c;
      string ntt = p.Division__c;
      if(ott!=ntt&&ntt=='Work Injury'){
        nst=true;
      }
      system.debug('!!!!!!!!!!!!ott'+ott);
      system.debug('!!!!!!!!!!!!ntt'+ntt);
      system.debug('!!!!!!!!!!!!nst'+nst);
    
    }

  if(lst.size()>0){insert lst;lst.clear();}    
    if(nst){
      OnceARc.setAlreadyRound();
      Accounts_Receivable__c st = new Accounts_Receivable__c(
      Treatment_Plan_Object__c =p.Id
      );
      lst.add(st);
      if(lst.size()>95){insert lst;lst.clear();}    
    }
  }
  if(lst.size()>0){insert lst;lst.clear();}    
}

}catch(Exception exall){}
}
Best Answer chosen by BenBurbridge(JP)
Jen BennettJen Bennett
I didn't read through the entire trigger but I did notice that on this line...
if(lst.size()>0){insert lst;lst.clear();}

you have a close bracket instead of an open bracket ( } should be { )