Skip to main content
Ankita Gupta (TCS) ha preguntado en #Apex
I'm a little new to exception handling. I've created a very basic scenario where I want to handle an exception in trigger.

Picklist values in field TestPicklist__c of object TestException__c: Yes, No

I'm updating this field with other value than Yes/No so that exception is throw.

trigger TestExceptionHandling on TestException__c (before insert) {

if(trigger.isBefore && trigger.isInsert)

{

    try{

    for(TestException__c testObj:trigger.New)

    {

          

        testObj.TestPicklist__c='Undecided';

        

        

    }

    }

    catch(Exception e)

        {

            System.debug('Error is here'+e.getMessage());

           

        }

}

}

But this code does not give anything in debug logs. Plus the message on page is Salesforce specific message for an error. I want to see the error in debug logs as well.

'Error: Invalid Data. 

Review all error messages below to correct your data.

Apex trigger TestExceptionHandling caused an unexpected exception, contact your administrator: TestExceptionHandling: data changed by trigger for field TestPicklist: bad value for restricted picklist field: Undecided'
2 respuestas
  1. 23 feb 2017, 11:31
    Hi Ankita,

    you can five any value to picklist and it will save that value irrespective of values available for picklist. You can say it is a advantage/disadvantage in SFDC for picklist. Try with any numeric data type with basic devide by zero error.

    Hope it helps :)