function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tan JTan 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.
Tan JTan J
Also, I have tried using database.insert and moving history record creation to @future method. It did not help.
Rakesh BoinepalliRakesh 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 JTan J
@Rakesh: have already tried that.
Rakesh BoinepalliRakesh 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 JTan J
@Rakesh: I am facing this issue: http://salesforce.stackexchange.com/questions/23462/record-insert-gets-rolled-back-if-reentrancy-flag-exists/110358#110358