You need to sign in to do that
Don't have an account?
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){}
}
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){}
}
you have a close bracket instead of an open bracket ( } should be { )