Trigger.new:

  • 1. Trigger.new - is used to access the new versions of the records that are being processed by the trigger.
  • It returns a list of sObjects (records) of the type specified in the trigger context.
  • 2. It is commonly used in before triggers to inspect and modify the incoming records before they are saved to the database.

  • Example:-


Trigger.newMap:

1. Trigger.newMap is used to access the new versions of the records in a map format, where the keys are the record IDs and the values are the corresponding records.

2. It is useful when you need to compare old and new values of a field or when you want to perform operations based on the record ID.

Example:


When working with Trigger.newMap, you can easily retrieve the old values of the records using Trigger.oldMap, which is especially helpful in before update triggers.

Example:

In summary, Trigger.new provides a list of new records, while Trigger.newMap provides a map of new records with their IDs as keys. The choice between them depends on the specific requirements of your trigger logic.