function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

System.NullPointerException: Script-thrown exception



Im getting the error message when I update a case record:


Error: Invalid Data.

Review all error messages below to correct your data.
Apex trigger Case_CopyConsignmentNumber caused an unexpected exception, contact your administrator: Case_CopyConsignmentNumber: execution of BeforeInsert caused by: System.NullPointerException: Script-thrown exception: (System Code)


I'm trying to search the description field for a unique text string (2 letters followed by 6 letters) and populate the Tracking_job_number__c field with this unique string if this is found.



trigger Case_CopyConsignmentNumber on Case (before delete, before insert) {
        if(c.Description!= null && c.Tracking_Job_Number__c == null){
            // First, instantiate a new Pattern object
            Pattern MyPattern = Pattern.compile('[A-Z]{2}\\d{6}|[a-z]{2}\\d{6}]');
            //return a string that contains only numeric values from 0-9 from my original input
            String ConsignmentNumber = MyPattern.matcher(c.Tracking_Job_Number__c).replaceAll('');
                System.debug('>> found'+ConsignmentNumber);


bob_buzzardbob_buzzard isn't available on delete triggers - its only available on insert and update. Thus when a case is deleted I'd expect this to throw an error.