You need to sign in to do that
Don't have an account?
Matthew Holdgate
Apex code issue unexpected error
Hi
I have the Apex code and have no idea about Apex code or triggers so I can't solve any issues that appear. I get this error when creating a new record.
Apex trigger DOUM_SetTermsConditions caused an unexpected exception, contact your administrator: DOUM_SetTermsConditions: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.DOUM_SetTermsConditions: line 4, column 1
Any ideas as to how I can fix it?
I have the Apex code and have no idea about Apex code or triggers so I can't solve any issues that appear. I get this error when creating a new record.
Apex trigger DOUM_SetTermsConditions caused an unexpected exception, contact your administrator: DOUM_SetTermsConditions: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.DOUM_SetTermsConditions: line 4, column 1
Any ideas as to how I can fix it?
trigger DOUM_SetTermsConditions on DOUM_Version__c (before insert, before update) { Map<Id,Id> cases = new Map<Id,Id>(); List<DOUM_Version__c> listGL = new List<DOUM_Version__c>(); listGL = [Select DOUM_Terms_Conditions__r.Name, DOUM_Terms_Conditions__c from DOUM_Version__c where Id In: trigger.newMap.keySet() AND DOUM_Terms_Conditions__c <> null]; for(DOUM_Version__c objGL: listGL) { cases.put(objGL.id,objGL.DOUM_Terms_Conditions__r.Name); } for (DOUM_Version__c a : Trigger.new) { if(a.DOUM_Terms_Conditions__c != null) { a.DOUM_Terms_Conditions__c = cases.get(a.DOUM_Terms_Conditions__c); } } }
Try this ,
Let me know if this works or not.
Mark is solved by selecting a best answer. if it solves the problem.
What I want to happen is I have a filtered lookup field on the object DOUM_Version looking upon an object called DOUM_Terms_Conditions. The lookup field is called "DOUM_Terms_Conditions__c"
The terms and conditions object has fields: (Label-Name[API]-Type)
"Terms & Conditions V" - Name - Auto Number (Unique Primary ID)
"Active Date" - DOUM_TCs_A_D__c - Date
"Approval Status" - DOUM_TCs_Approval_Status__c - Picklist
"Retired Date" - DOUM_TCs_RD__c - Date
"Terms & Conditions" - DOUM_TCsContent__c - Rich Text Area
The filter on the lookup basically looks for the only record that doesnt have a retirement date.
I was wondering if it may be the filter that is breaking this trigger?
I dont think It's the filter. Error is on Line 4 Column 1, Which is a SOQL statement.
Try above then we will see what else can be done .
Regards
Abhilash Mishra.
I now get this error. This strikes me as it's trying to pull a record ID but receiving the unique name which is "Terms & Conditions V01"
We made progress
Kindest regards
Matt
This error is occurring before update. we will get to it. but first can you check whether trigger is working correct for insert or not.
just try to insert a new record.
you can contact me on abhilash.udit@gmail.com for Quick conversation about this problem.
i will be happy to help.
Regards
Abhilash
my code is