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
StormConsultingStormConsulting 

Simple update set of records

In Apex/Eclipse, how can I perform this simple update:

UPDATE bookings SET field1 = 'a', field2 = 'b', field3 = 'c' WHERE set_id = 999

So all I want to do is update all the records with the set_id that I specify. bookings would be my custom object.

Cheers
werewolfwerewolf
Just select out the objects that meet your where clause, then set those values on the fields in the returned objects, then call update on those objects.
StormConsultingStormConsulting
This won't work because when calling the update from the before update trigger, the entire trigger is called again, and ends up erroring saying can't update self record. If it didn't do that error, it would get stuck in a infinite loop.

Is there a way to store the Ids that have been updated in a static List? Then check the list before updating. I tried this but did not seem to work.

I have even tried checking if the record has been updated in the last 10 seconds, only if that is false do the update. This does not work because the before update trigger can not access the lastUpdated field.
werewolfwerewolf
Well if you're in the before update trigger then you can just update fields on the objects that triggered the trigger and call update on them.  That will not recall your Apex trigger.
StormConsultingStormConsulting
That would work if I was only ever updating the records with the same data. But what I wanted was to update the other records with the data from the record that was editted by the user.

I have got it working by using a boolean in a static class. When the trigger fires is checks the boolean, if its false, the trigger skips all the code. So just before I call the update DML, I set this boolean to false, so when it fires the trigger, it appears not to run.