I have a custom object called AppDoc__c which has a master-detail relationship with Case.
I have a process builder on case which creates 3-records of AppDoc__c everytime a new case is created.
Value of Child records:
Case - Field Reference - Case.Id
Now, I have an after Insert trigger on AppDoc__c, which uses the case field of AppDoc__c. But I am getting an error
Can’t Save Record
We can't save this record because the “New AppDoc Upon Case Creation” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: AppDocTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.AppDocHandler.push: line 6, column 1 AppDocTrigger: line 21, column 1. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 1143198561-45111 (378836202)
Here the line of the AppDoc Handler that is throwing the error is actually the line accessing the Case field of AppDoc.
I am not exactly sure why this error is happening, as Process Builder on Case should create the AppDoc with corresponding Case Id, before it is accesses by Case.