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

If one record in batch fails entire batch fails- apex triggers
Hello,
I have an Apex trigger (after insert) on Opportunity which updates the Contact on that Opportunity upon insert. While inserting thousands of Opportunities via Data loader, the 199 Opportunities are inserted but 199 Contacts are not updated for the whole batch if one opportunity insert fails in a batch of 200 records.
Do you know of a way where trigger does a partial update of the batch with successful inserts.
I tried using try and catch, Database.SaveResult[] result = Database.update(contactList, false); but no luck
Can anyone suggest how to resolve this?
I have an Apex trigger (after insert) on Opportunity which updates the Contact on that Opportunity upon insert. While inserting thousands of Opportunities via Data loader, the 199 Opportunities are inserted but 199 Contacts are not updated for the whole batch if one opportunity insert fails in a batch of 200 records.
Do you know of a way where trigger does a partial update of the batch with successful inserts.
I tried using try and catch, Database.SaveResult[] result = Database.update(contactList, false); but no luck
Can anyone suggest how to resolve this?
Your code for Contact update is correct but issue is in opportunity insert itself so data loader opportunity insert is failed. You could reduce the size of Batch in DataLoader to 1 to resolve it.
Thanks
Thanks for your response! We are already inserting with batch size 1 but we have thousands to load each time and its time consuming so I was wondering if there is a way to improve this one.
Thanks