You need to sign in to do that
Don't have an account?
Tan J
Trigger rolls back the transaction - doesn't save records though I can see SF ID in debug
I have two objects A & B. B is child of A in lookup relationship. There are existing complex triggers on both of these objects. One of the thing which trigger on object A does is whenever field xyz changes; it updates all the child object B records with the new value of field xyz. (Both of these objects have field xyz which is long text area.)
As per new requirement, I have to track field history for both of the above objects in custom object (history object C). So I wrote some complex logic to track the history which gets called from object A and Object B trigger. This works fine except one scenario where if I change field xyz on object A and one of the object B child record is erroneous (data does not meet vaidations - coded in before trigger). In this case my history records are not created for any of these object B child records including erroneous and non-erroneous records. When I put debug after insert statements, I can see that even SF ID's are created for these history records. When I search a record with that SF ID , it says that 'the data you are trying to access could not be found...'. (Note: I use some static maps to avoid duplicate history record creation because of recursive trigger; in case if it matters). Please let me know if anyone has come across this situation before.
As per new requirement, I have to track field history for both of the above objects in custom object (history object C). So I wrote some complex logic to track the history which gets called from object A and Object B trigger. This works fine except one scenario where if I change field xyz on object A and one of the object B child record is erroneous (data does not meet vaidations - coded in before trigger). In this case my history records are not created for any of these object B child records including erroneous and non-erroneous records. When I put debug after insert statements, I can see that even SF ID's are created for these history records. When I search a record with that SF ID , it says that 'the data you are trying to access could not be found...'. (Note: I use some static maps to avoid duplicate history record creation because of recursive trigger; in case if it matters). Please let me know if anyone has come across this situation before.
Tan J
Also, I have tried using database.insert and moving history record creation to @future method. It did not help.
Rakesh Boinepalli
Salesforce rollbacks the entire transaction if any run time exception occurs. Use Database.insert(list_to_insert,false) method which basically fails only records which doesn't meet validations. Thanks!.
Tan J
@Rakesh: have already tried that.
Rakesh Boinepalli
In the same debug log, do you see any other run time exceptions?. Clearly records are saving into database (because of record id's), but not commiting due to some exception. We need to put some debug stataments in the code to identify the culprit.
Tan J
@Rakesh: I am facing this issue: http://salesforce.stackexchange.com/questions/23462/record-insert-gets-rolled-back-if-reentrancy-flag-exists/110358#110358