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
Guyver118Guyver118 

Bulk trigger idiom

I was wondering if i only want a trigger to only happen on the interface i.e. as don't want this to happen in a bulk upate in data loader can i just always just manipulate the first record on the trigger list

 

//Some trigger on account which should only happen in user interface

 

Account acc = trigger.new.get(0);

 

//do some stuff with acc?

Best Answer chosen by Admin (Salesforce Developers) 
crop1645crop1645

Guyver:

 

  1. While you may think that the trigger will only fire for the user interface use case; you may find down the road that you need to do bulk updates using the Data Loader or Excel Connector and you will regret this shortcut.  I know, I did.  Therefore, best practice is to always write triggers using the bulk trigger idiom which is well documented in the SFDC Apex Developer Guide and also in the Force.com Cookbook. 
  2. To your specific question, the expression: Trigger.new is a List of whatever sObject your trigger is written for.  Therefore, the first (and only) element will always be the record triggered by the UI.
Message Edited by crop1645 on 11-09-2009 09:56 AM