I need to update the fields of a few records (around 20) that were existing before I made a trigger. I know that before triggers cannot update existing records (or can they ?) but I think that using batch apex for such a small number of records may not be the best solution. Is there a different way to update these records or do I still need to use a batch ?
closed as unclear what you're asking by battery.cord, Jayant Das, Pranay Jaiswal, Mohith Shrivastava, Reshma Mar 18 at 12:10
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
It depends on if it is before insert or before update. If it is only before insert, you will need to manually update the records. If it is before update, you can usually just run an execute anonymous script:
update [select id from objecttype where somefield = null];
1) Yes, You can update the existing records on same object trigger. You need to make sure the trigger do not convert on recursive mode.
2) Batch calss is npt a good solution to do DML for small number of records but you can use asynch call to do the process.