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
davidesidavidesi 

Trigger.new operation

¿Can anybody explain me what is the operation of the Trigger.new ?

 

When I create an opportunity, for example, and a trigger is executed , Trigger.new shouldn't store ONLY that opportunity that I have created?

 

Why I get a lot of opportunitys in the Trigger.new collection?

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
davidesidavidesi

Thank you for your reply Vinit.

 

I knew that page that you have referred me, but I don' understand the behaviour.

 

If I add a Trigger wich is executed when it is created, isAfter , why am I getting more than 1 record in the list?

 

 

All Answers

Vinit_KumarVinit_Kumar

Trigger.new is List which contains new versions of sobject on which the operation is being performed.Please find below link to know more :-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm

davidesidavidesi

Thank you for your reply Vinit.

 

I knew that page that you have referred me, but I don' understand the behaviour.

 

If I add a Trigger wich is executed when it is created, isAfter , why am I getting more than 1 record in the list?

 

 

This was selected as the best answer
Vinit_KumarVinit_Kumar

Davi,

 

It is not that you are getting more than one record in the list.It is just that you have more than one values (I mean all the fields of that record,it is contained in the list).

 

So,it is the collection of all the values of that record ehich are stored in the list as Trigger.new.

davidesidavidesi

Thanks Vinit.

 

In the trigger log , I see following line (it's only a line).

And every id belongs to an individual object.

 

PD: What is a Kudo?

12:00:48.690 (1690879000)|CODE_UNIT_FINISHED|updateRatecount on Choose_Rate trigger event BeforeUpdate for [a0AD000000NCmnF, a0AD000000NCmnG, a0AD000000NCmnH, a0AD000000NCmnt, a0AD000000NCmnu, a0AD000000NCmnv, a0AD000000NCmnw, a0AD000000NCmnx, a0AD000000NCmny, a0AD000000NCmnz, a0AD000000NCmo0, a0AD000000NCmo1, a0AD000000NCmo2, a0AD000000NCmo3, a0AD000000NCmo4, a0AD000000NCmo5, a0AD000000NCmo6, a0AD000000NCmo7, a0AD000000NCmo8, a0AD000000NCmo9, a0AD000000NCmoA, a0AD000000NCmoB, a0AD000000NCmoC, a0AD000000NCmoD, a0AD000000NCmoE, a0AD000000NCmoF, a0AD000000NCmoG, a0AD000000NCmoH, a0AD000000NCmoI, a0AD000000NCmoJ, a0AD000000NCmoK, a0AD000000NCmoL, a0AD000000NCn03, a0AD000000NCn04, a0AD000000NCn05, a0AD000000NCn06, a0AD000000NCn07, a0AD000000NCn08, a0AD000000NCn09, a0AD000000NCn0A, a0AD000000NCn0B, a0AD000000NCn0C, a0AD000000NCn0D, a0AD000000NCn0E, a0AD000000NCn0F, a0AD000000NCn0G, a0AD000000NCn0H, a0AD000000NCn0I, a0AD000000NCn0J, a0AD000000NCn0K, a0AD000000NCn0L, a0AD000000NCn0M, a0AD000000NCn0N, a0AD000000NCn0O, a0AD000000NCn0P, a0AD000000NCn0Q, a0AD000000NCn0R, a0AD000000NCn0S, a0AD000000NCn0T, a0AD000000NCn0U, a0AD000000NCn0V, a0AD000000NCn0W, a0AD000000NCn0X, a0AD000000NCn0Y, a0AD000000NCn0Z, a0AD000000NCn0a, a0AD000000OgKEP, a0AD000000OgKEZ, a0AD000000OgM8e, a0AD000000OgMlQ, a0AD000000OgMmd, a0AD000000OgTMx, a0AD000000OgTWU, a0AD000000OgTWZ, a0AD000000OgTXw, a0AD000000OgTYQ, a0AD000000OgYLb, a0AD000000OgzHe, a0AD000000Ogztv, a0AD000000Oh5uV, a0AD000000OhD6B, a0AD000000OhD6C, a0AD000000OhD8l, a0AD000000OhDG5, a0AD000000OhGWw, a0AD000000OhHNQ, a0AD000000OhMEV, a0AD000000OhMEb, a0AD000000OhMaW, a0AD000000OhMaX, a0AD000000OhMfb, a0AD000000OhMxx, a0AD000000OhMyQ, a0AD000000OhSxG, a0AD000000OhTCa, a0AD000000OhUWC, a0AD000000Ohjo1, a0AD000000OhjoB, a0AD000000Ohjs8, a0AD000000Ohk7O, a0AD000000Ohwk8, a0AD000000Ohwlk, a0AD000000QCH4k, a0AD000000QCH6n, a0AD000000QCYvX, a0AD000000QCYwa, a0AD000000QCotC, a0AD000000QCqfH, a0AD000000QCqhe, a0AD000000QCtae, a0AD000000QCxM3, a0AD000000QCxOe, a0AD000000QCxlN, a0AD000000QCyT5, a0AD000000QCyT6, a0AD000000QD7i0, a0AD000000QDAnp, a0AD000000QDAqd, a0AD000000QDBDY, a0AD000000QDbvS, a0AD000000QDbvh, a0AD000000QDzWP, a0AD000000QE008, a0AD000000QE6VR, a0AD000000QE6Vq, a0AD000000QE6Wt, a0AD000000QEI7a, a0AD000000QEJTc, a0AD000000QEJpC, a0AD000000QEW1M, a0AD000000QEW3S, a0AD000000QEktX, a0AD000000QEoHm, a0AD000000QEoTK, a0AD000000QEscP, a0AD000000QFbkb, a0AD000000QFbms, a0AD000000QFbo3, a0AD000000QFboy, a0AD000000QFbpO, a0AD000000QFbqM, a0AD000000QFcAS, a0AD000000QFcDG, a0AD000000QFcEC, a0AD000000QFcEH, a0AD000000QFcER, a0AD000000QFcGe, a0AD000000QFcI8, a0AD000000QFcJS, a0AD000000QFcOD, a0AD000000QFcOI, a0AD000000QFcPm, a0AD000000QFcQ9, a0AD000000QFcSY, a0AD000000QFcSd, a0AD000000QFuK4, a0AD000000QFuSN, a0AD000000QGGiQ, a0AD000000RpIby, a0AD000000RpL4e, a0AD000000RpbNz, a0AD000000RpdQq, a0AD000000RpdRV, a0AD000000RpezD, a0AD000000RpfCl, a0AD000000RpfEo, a0AD000000RpfEy, a0AD000000Rpi9F, a0AD000000RptBs, a0AD000000RqBlH, a0AD000000RqVhC, a0AD000000RqWIK, a0AD000000RqZ5y, a0AD000000RqZBw, a0AD000000RqmSH, a0AD000000RqqF9, a0AD000000RrbKO, a0AD000000Rro8Q, a0AD000000Rro8k, a0AD000000RroMJ, a0AD000000RroPr, a0AD000000RroT3, a0AD000000Rrwpb, a0AD000000Rrwpg, a0AD000000RrxH0, a0AD000000RrxHA, a0AD000000RrxOc, a0AD000000RrxOm, a0AD000000RrzNE, a0AD000000RrzNY, a0AD000000RrzPZ, a0AD000000RrzsM, a0AD000000Rs01U, a0AD000000Rs42R, a0AD000000Rs46Z, a0AD000000Rs48U, a0AD000000Rs9ni, a0AD000000Rs9oV, a0AD000000Rs9tn, a0AD000000RsA3Z]
12:00:48.701 (1701578000)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Choose_Rate:a0AD000000NCmnF



Vinit_KumarVinit_Kumar

When you print Trigger.new.You will see all the field values in the debug log.

 

What you are seeing is because the Trigger is running on multiple records.

 

As per Kudos ,it is the star ('*') button below my name in the my post.If you like the post,you can hit it to thank me.

davidesidavidesi

That's what I don't understand.

If I am creating a single record, why that trigger runs over multiple records?

Vinit_KumarVinit_Kumar

The trigger you see in Debug log is not on insert event,it is on update event.

 

updateRatecount on Choose_Rate trigger event BeforeUpdate for

 

I think what is happening here is that the record you are inserting , is updating any field available on these records causing the Update Trigger to fire.