Before Trigger Context Variable in Salesforce | Modify Field Values

Modify Field Values in Salesforce Before Trigger | DEV-501 Exam Answer

Question

Which trigger context variable allows you to modify field values before they are written to the database in the before trigger?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D.

The correct answer to this question is option D: Trigger.new.

In Apex, a trigger is a piece of code that is executed before or after a record is inserted, updated, or deleted. When a trigger is executed, it is provided with a set of trigger context variables that allow it to access information about the event that caused the trigger to fire.

One of these context variables is Trigger.new, which is used in a "before" trigger to access the new version of the records that are being inserted or updated.

By modifying the field values in Trigger.new, you can change the values that will be written to the database. For example, you could use Trigger.new to automatically populate a field or to enforce certain business rules.

Option A, @ReadOnly, is not a trigger context variable. It is a special annotation that can be used to mark a class or method as read-only, which means that it cannot modify data in the database.

Option B, RETURNING, is not a trigger context variable either. It is a SQL keyword that is used to specify the values that should be returned from a query.

Option C, Webservice, is also not a trigger context variable. It is a keyword that is used to define methods that can be exposed as web services.