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
balaji raobalaji rao 

System.DmlException: Insert failed. First exception on row 0; first erro

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, COH_BP_FeedItemTrigger: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.COH_BP_FeedItemHelper.processNewFeedItems: line 354, column 1
Trigger.COH_BP_FeedItemTrigger: line 15, column 1: []

please help on the above error
Khan AnasKhan Anas (Salesforce Developers) 
Hi Balaji,

Greetings to you!

According to Salesforce knowledge article (https://help.salesforce.com/articleView?id=000063739&type=1):

This error is caused by a line of code that is trying to use an object that has not been instantiated, or an object's attribute that has not been initialized.

NOTE: If the field Site was left empty, it will generate the error message as well.

The solution is to make sure the Object and/or the Attribute to be used is not null. In this example, the code needs to be modified as follows:
Account newAccount = accountMap.get(oldAccount.Name);

        if (newAccount != null) 

          if (newAccount.Site != null) 

            i = newAccount.Site.length();

Exception handling routine:
Account newAccount = accountMap.get(oldAccount.Name);

        try {

             i = newAccount.Site.length();

            }
            catch (System.NullPointerException e) {

            e1 = e; // can be assigned to a variable to display a user-friendly error message

        }

For more information on handling exceptions, check the Apex Language Reference, under "Using Exception Methods," or "Using Exception Variables. (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_exception_methods.htm)"

For more information on initializing variables, look under Chapter 2, "Language Constructs", in the topics "Variables", and "Case Sensitivity (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_datatypes_variables_intro.htm)".

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas​​​​​​​