You need to sign in to do that
Don't have an account?
Waqar Hussain SF
Trigger to create child records, I am getting error while I create a record. Here is my trigger
trigger createSal on Employee__c (after insert, after update) {
List<Salary__c> sal = new List<Salary__c>();
for (Employee__c newEmp: Trigger.New) {
if (newEmp.Name != null) {
sal.add(new Salary__c(Id = newEmp.Id, Bonus__c=100,Monthly_Salary__c = 12000));
}
}
insert sal;
}
List<Salary__c> sal = new List<Salary__c>();
for (Employee__c newEmp: Trigger.New) {
if (newEmp.Name != null) {
sal.add(new Salary__c(Id = newEmp.Id, Bonus__c=100,Monthly_Salary__c = 12000));
}
}
insert sal;
}
All Answers
sal.add(new Salary__c(Id = newEmp.Id, Bonus__c=100,Monthly_Salary__c = 12000));
you cannot set id of a record.. i think you should replace id with your employee look up field api name.
thanks,
http://www.forcexplore.com/2014/07/salesforce-adm-201-dumps-part-14.html
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger createSal caused an unexpected exception, contact your administrator: createSal: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: a0V9000000JYW2iEAH: Trigger.createSal: line 7, column 1
sal.add(new Salary__c(Employee__c = newEmp.Id, Bonus__c=100, Monthly_Salary__c = 12000));
I found this link - http://developer.force.com/cookbook/recipe/creating-a-child-record-when-a-parent-record-is-created.
Hope this helps.