+ Start a Discussion
Romeo MirzacRomeo Mirzac 

Problem with database.update in try...catch

I have written a try...catch statement, in an Apex Trigger.

This routine runs as part of a trigger which evaluates field names.  However, if an invalid field name is passed in, I want to deactive the template record..  This routine works fine IF I remove the objCase.adderror line (the template is marked Inactive).  BUT then I don't get an error on the page.  Any suggests on why this is occurring and how I can resolve it?


         String strCompare =string.valueOf(objCase.get(fieldName));
            return strCompare;
        } catch(Exception ex){

            aplusTemplate theTempl = new aplusTemplate(false);
            system.debug('TriggerHandler: ' + templateName);
            String strMsg ='Error with Aplus Template: ';
            strMsg +='An invalid field name on Template (' + templateName + ') ';
            strMsg +='caused a problem. ';
            strMsg += 'This template will be deactivated until the issue can be resolved. ';
            strMsg +='Please report this issue to you system administrator.  ';
            strMsg +='Please try to SAVE the record again. ';


My goal is to disable the tea
Take a look to see what exception is actually firing as you don't look at ex to see.  
Kiran  KurellaKiran Kurella
It looks like you want to update the template record and throw an error to the user. If it is the case, then you should use @future method to update the Template Record.