2

I've noticed in triggers it is not necessary to use CRUD calls as it is in apex classes. However if I am updating a field on a different object to the one the trigger is on, do I need to do it then?

Basically when a contract is activated, I need to mark an opportunity that is related to it (with a custom field) as closed won.

1

The only time that you don't need to call insert, update or upsert in a Trigger is then you are in a Before trigger and you are modifying the record that the Trigger is on, this is because the Trigger is running before the records are actually committed to the database, so after the trigger is run the objects will be committed by the platform. For all other scenarios you need to call insert, update or upsert

2

In a before trigger you can make changes to the records which have caused the trigger to fire, and you don't have to explicitly CRUD them.

If you update records on another object, or records on the same object but not in this trigger context then you need to be explicit with an update for this to work.

For example if you have a before update trigger on your contract object, and record A is updated, then you can make any changes you want to record A in the trigger without calling doing an explicit update. If you want to update other Contract records which aren't in the trigger or you want to update Opportunities then you do need to call database update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.