You need to sign in to do that
Don't have an account?
Does the new in trigger.new mean it works only on the new incoming leads?
trigger testTrigger on Lead (before insert, before update) { for(Lead l: trigger.new){
Does trigger.new mean the trigger only works on the new lead that just came in and if a bulk insert then it will work on all the new bulk leads only and none of the existing leads?
The reason I ask, is that i want to modify an incoming lead from Web2Lead form and the only way I can imagine to get access to the data being inserted as a lead from the Web2Lead is to set a trigger to grab the lead before insert, but want to find a way to mod only the incoming lead that just happened.... So when I play with "Select" I want to be sure that I will only be selecting the newly arrived lead before it has yet been inserted. I assume if I tamper with it here i can change it before it enters the data base.
Is there a special "Select" statement that I would use to "Select" modify and then "Update" the lead as it is inserted?
Trigger.new is the "new" information that will be submitted to the database after the transaction completes. Trigger.old, in contrast, is the information that WAS in the database before the transaction started. For insert and undelete operations, there won't be any "old" information (Trigger.old will be null), and for deletions, there won't be any "new" data (Trigger.new will be null). Trigger.old and Trigger.new allow a developer to detect changes between the old values and new values during an "update" operation.
More to the point, as it relates to your inquery, the "before insert" part on line one is what tells the database to run this code when a record is created; "before update" indicates that it will run when an existing record is updated (e.g. a user presses "edit", makes some modifications, and then presses "save"). Trigger.new is simply the data that will be committed to the database. By modifying the values in Trigger.new, you will directly modify the data that will be committed to the database.
You may consider taking a short tutorial on SQL to understand CRUD (create, read, update, delete), which will help you visualize how triggers operate within salesforce.com.
All Answers
Trigger.new is the "new" information that will be submitted to the database after the transaction completes. Trigger.old, in contrast, is the information that WAS in the database before the transaction started. For insert and undelete operations, there won't be any "old" information (Trigger.old will be null), and for deletions, there won't be any "new" data (Trigger.new will be null). Trigger.old and Trigger.new allow a developer to detect changes between the old values and new values during an "update" operation.
More to the point, as it relates to your inquery, the "before insert" part on line one is what tells the database to run this code when a record is created; "before update" indicates that it will run when an existing record is updated (e.g. a user presses "edit", makes some modifications, and then presses "save"). Trigger.new is simply the data that will be committed to the database. By modifying the values in Trigger.new, you will directly modify the data that will be committed to the database.
You may consider taking a short tutorial on SQL to understand CRUD (create, read, update, delete), which will help you visualize how triggers operate within salesforce.com.
There's no need to select the incoming data; it's handed to you on a silver platter. Consider the following code:
You will only need to select data that isn't part of the DML operation (such as related records).