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
madhan bondalapatimadhan bondalapati 

Trigger Upsert?

i am inserting 100 records inthat 50 insert,50 update through workbench.what will be the size of the trigger.new() .Whether it will 50 or 100?
 
Best Answer chosen by madhan bondalapati
Mahesh DMahesh D
Hi Madhan,

Trigger will fire for 2 times, one for insert records and in this context Trigger.new will be 50 and 
second time trigger will fire for update records and in this context Trigger.new and old will be 50.

Regards,
Mahesh

All Answers

@Karanraj@Karanraj
Trigger.New will hold all the record whether its inert or update. The answer for your question is 100
Mahesh DMahesh D
Hi Madhan,

Trigger will fire for 2 times, one for insert records and in this context Trigger.new will be 50 and 
second time trigger will fire for update records and in this context Trigger.new and old will be 50.

Regards,
Mahesh
This was selected as the best answer
Mahesh DMahesh D
Hi Madhan,

Below is the results from my test

I did a upsert of 5 Cases (2 new and 3 existing) and the results below:

CaseTriggerNew on Case trigger event BeforeInsert for [new, new]

CaseTriggerNew on Case trigger event BeforeUpdate for [5003600000167tx, 5003600000167vA, 50036000001HLfY]

Hope this is helpful.

Regards,
Mahesh
madhan bondalapatimadhan bondalapati
@mahesh For update whether we use ,trigger.new() or trigger.old() both are same right.

I have one doubt for many records we will get exception?
Mahesh DMahesh D
Hi Madhan,

Yes when we do update both are same but you can't do update for the mix of new and existing records.

Regards,
Mahesh