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
jdeveloperjdeveloper 

question on trigger.New

hi lets say we have trigger that is triggered when object__c is update. then what does for (Object__c c: Trigger.New) mean. Is it a for each loop that goes through every record that has just been updated for the object__c

Best Answer chosen by Admin (Salesforce Developers) 
Devendra NataniDevendra Natani

Hi,

 

Trigger.New  returns the List<Object__c>. If you update a single record then it returns a list of one record for that object. 

If you update multiple records at a time, then it will return the list of all records.

 

Using that

 (Object__c c: Trigger.New)

 

We iterate over the list of Object__c. 

 

All Answers

Devendra NataniDevendra Natani

Hi,

 

Trigger.New  returns the List<Object__c>. If you update a single record then it returns a list of one record for that object. 

If you update multiple records at a time, then it will return the list of all records.

 

Using that

 (Object__c c: Trigger.New)

 

We iterate over the list of Object__c. 

 

This was selected as the best answer
Nilesh ManeNilesh Mane

To update an existing record, you must use trigger.old

trigger.old gives you list of older version of records.

you can fetch the record, which matches certain criteria and you can update it easily.

 

Use 

(Object__c c : trigger.old)