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
faceroy123faceroy123 

System.NullPointerException: Script-thrown exception

Hi,

 

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) {
    
    for(Case c:Trigger.new){
        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('');
            
            if(ConsignmentNumber!=null){
                System.debug('>> found'+ConsignmentNumber);
                c.Tracking_Job_Number__c=ConsignmentNumber;
            }
        }
    }}

 

bob_buzzardbob_buzzard
trigger.new 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.

See: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm