2

I've few questions on triggers

  1. In an insert trigger, Can I update a field and use that field in where clause of SOQL Query? so same transaction is updating and querying field.

  2. difference between before update and after update trigger.

diff in Before insert and after insert i know, through after insert trigger, i can get record ID. update triggers have access to IDs. so which situation warrants use of 'after update' triggers?

  1. trigger.old can be referenced in 'after' triggers or not

1 Answer 1

3

1) In insert: You can update a field here. In after you can query for the updated field here.

2) before means before the record has been saved to the database. That means anything you change in here will be saved into the database. after means the record has been saved/committed to the database. This is when the Id is first populated in an insert.

You use after update triggers if you aren't making any changes to the record before it saves in the database.

The only time you can't reference Trigger.old is in: any insert and any undelete.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .