Showing posts with label dmlexception. Show all posts
Showing posts with label dmlexception. Show all posts

Thursday, November 8, 2018

Handle exception by Try, Catch and Finally statement in Apex in Salesforce.com

Try-Catch-Finally Statements Syntax:

try {

      //Perform some operation that might cause an exception.

} catch (exception e){ 

      //Handle generic exception here.

} 
catch (dmlexception de){ 

      //Handle dml exception here.

} finally { 

      //this block of code always execute and allows you to clean up your code.

}

Apex Code

try {
  // Perform some operation that might cause an exception.
    Merchandise__c m = new Merchandise__c();
    insert m;

    // This doesn't execute since insert causes an exception
    System.debug('Statement after insert.');

} catch (Exception e) {
    
   // Handle generic exception here.
   }catch(DmlException e) {
    System.debug('The following exception has occurred: ' + e.getMessage());
    
 } finally {
    // Perform some clean up.
}










Validation in flow input text field in sfdc: Maximum 255 characters limit

The input text field validate in sfdc flow behaves opposite of the generic sfdc validation rule.  Here the validation formula is evaluating ...