1

I get this error 7 times for 7 different classes.

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trgr_DocoSilentMode: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.trgr_DocoSilentMode: line 7, column 1: [] Stack Trace: Class.Test_siteEventOriginizer.site_eventContactDetailsTest: line 160, column 1

This is the trigger code. What is the issue? Thanks.

trigger trgr_DocoSilentMode on Project__c (after update) 
{

    List<Project__c> opNew;
    Map<ID,Project__c> opOld;

     for(Project__c prj : opNew)
            {
                Project__c oldPrj = opOld.get(prj.id);

                if(prj.forms__c != oldPrj.forms__c)
                {
                    System.debug('DOCO IN');

                    //First remove all current attachments
                    removeCurrentAttachments(prj.id);

                    String docFormat = prj.forms__c;

                    //Send Multi Pickist values to generateDocument method
                    if(generateDocument(prj.Id, docFormat)) 
                    {

                    }  

                    // final
                    prj.forms__c = null;
                }
            }




    public void removeCurrentAttachments (String prjID) 
    {
        // Remove all current attachments on the document    

        List<Attachment> allAttachments = [Select ID, ParentID, body, Name from Attachment Where ParentID = :prjID AND Name LIKE '%Jafi - Education Office%'];

        // Only attempt to delete attachments if there is at least one   
        if(allAttachments<> Null) delete allAttachments;
    }

    public Boolean generateDocument (String prjID, String docFormat)
    {
//      System.debug('DOCO: ' + 'prj: ' + prjID + ', docFormat: ' + docFormat);

        // This method generates the docomotion documents as per the parameters that are passed to it    
        try{

                if(docFormat != Null && docFormat.contains('Education Office')) 
               {
                doco.RenderAPI.renderCreateFileAsync(4, prjID, doco.RenderAPI.Mode.Attachment, doco.RenderAPI.Format.Docx,'Jafi - Education Office ' + datetime.now() );
               }
        } 
        catch (Exception e)
        {
            System.debug('DOCO ERROR:' + e);
        }

        return True;
    }    

}

3 Answers 3

1

The list you have used in the for loop is null. The trigger should look like this.

trigger trgr_DocoSilentMode on Project__c (after update) 
{
   for(Project__c prj : trigger.new)
   {
     //to get the old value
     Project__c oldPrj = trigger.oldMap.get(prj.Id);
     if (prj.forms__c != oldPrj.forms__c)
     {
       // do something.
     }
   }
}

Hope this helps.

0

There are some basic issue with your code

  1. Your line 7 stating opNew which is list of project__c but you have not initialized it anywhere prior to using that. and I can see that you are iterating over it. so instead of that line you can iterate over Trigger.new which is list of current records as shown below.

    for(Project__c prj : Trigger.new)
    
  2. You are using opOld at line which seems like old records for records so you can replace that line with

    trigger.oldMap.get(prj.Id)
    
0

The problem is that you are not iniatilating the list

List<Project__c> opNew;
Map<ID,Project__c> opOld;

You should to start the list:

List<Project__c> opNew = Trigger.new;
Map<ID,Project__c> opOld = Trigger.oldMap;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .