You need to sign in to do that
Don't have an account?

How do I define a record that doesn't yet exist?
How do you create a new record on an object different from the trigger?
More specifically whenever I create a record in 1 object, I want to create a corresponding record in another object.
So far I have the following, but I get an error:
System.NullPointerException: Attempt to de-reference a null object
trigger UpdateLabor_After on Labor__c (after insert, after update) { String RelatedLabor = null, RelatedSchool = null, RelatedDistrict = null, temp_id = null; Labor__c[] labor = trigger.new; RelatedSchool = labor[0].Related_School__c; RelatedDistrict = labor[0].Related_District__c; if(System.Trigger.isinsert) { Student_Attendance_Labor__c [] newrecord; RelatedLabor = labor[0].Id; newrecord[0].Related_Labor__c = RelatedLabor; newrecord[0].Related_School__c = RelatedSchool; newrecord[0].Related_District__c = RelatedDistrict; insert newrecord [0]; }
The error looks like its related to the line:
Student_Attendance_Labor__c [] newrecord;
How do I define a record that doesn't yet exist?
If you are inserting just one record why bother with a List or Array?
if(System.Trigger.isinsert) { Student_Attendance_Labor__c newrecord = new Student_Attendance_Labor__c(); RelatedLabor = labor[0].Id; newrecord.Related_Labor__c = RelatedLabor; newrecord.Related_School__c = RelatedSchool; newrecord.Related_District__c = RelatedDistrict; insert newrecord; }
All Answers
If you are inserting just one record why bother with a List or Array?
if(System.Trigger.isinsert) { Student_Attendance_Labor__c newrecord = new Student_Attendance_Labor__c(); RelatedLabor = labor[0].Id; newrecord.Related_Labor__c = RelatedLabor; newrecord.Related_School__c = RelatedSchool; newrecord.Related_District__c = RelatedDistrict; insert newrecord; }