You need to sign in to do that
Don't have an account?
Insert child fields with 2 custom field
my parent custom object is Presupuesto__c, my child custom object is Movimiento_Presupuestal__c, i wanna create new field in child object with a trigger when i insert new parent field:
trigger calculosPresupuesto on Presupuesto__c (before insert, before update) {
}
but the error is:
Description Resource Path Location Type
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, calculosPresupuesto: execution of BeforeInsert
caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, required fields missings: [Cuenta__c]: [Cuenta__c]
You're doing:
for(Presupuesto__c p : pre)
The error you are getting is on "execution of BeforeInsert"
The reason for this is that on Before Insert triggers, all the records do not have their IDs assigned yet. Therefore this piece of code:
cuenta__c = p.Id
Assigns NULL to cuenta__c because p.Id is null.
Try doing this on an After Insert trigger and see if it works.