+ Start a Discussion
flewellsflewells 

Help bulkifying my trigger

I am looking for helping bulkifying a trigger I wrote that updates the Owner on Account.  I understand the concept of bulkifying and tried reviewing other posts where people have requested similar help, but am at a loss.  I'm a beginner and learning and happy to just have created the trigger below...any help in bulkifying is appreciated.  Also, does bulkifying this trigger mean that the test class I wrote also needs to be updated?

 

trigger UpdateOrganizationOwner on Account (before insert, before update) {
for (Account a : trigger.new) {

if (a.RecordTypeId == '012000000000000'&& a.RM_ID__c!=null) {
  a.OwnerId = a.RM_User_ID__c;
  }
 }
}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
The only concern here is the record type id should be queried (SELECT Id FROM RecordType WHERE DeveloperName = ...). Your code will properly run in bulk without modification.

All Answers

sfdcfoxsfdcfox
The only concern here is the record type id should be queried (SELECT Id FROM RecordType WHERE DeveloperName = ...). Your code will properly run in bulk without modification.
This was selected as the best answer
Rahul SharmaRahul Sharma
Also, does bulkifying this trigger mean that the test class I wrote also needs to be updated?

- It is always good practice to create more than 1 test record(Upto 200 records or so) and using asserts in test classes, This will help you to validate if your trigger is butlkified in your test class itself(Once you run it, you will get error if it is not bulkified - Using asserts).
avijchakavijchak

 

 

 

 

There is no SOQL in the TRIGGER hence no need to take extra care . Please avoid hard coding of Ids

flewellsflewells

Thanks to all of you for the tips.  I realized I don't need select the RecordType after all, so that simplified it even further.