You need to sign in to do that
Don't have an account?

Bulkify
Hello all,
I am a newbie to apex development. Can any one help me in bulkifying this trigger.
trigger PopulateRegistrantGroup on Event_Registrant_zem__c (before insert, before update) {
String s;
Id id1;
for (Event_Registrant_zem__c e :Trigger.new)
{
id1 = e.registrant_type__c;
s = [select id,name from Registrant_Type_zem__c where id = :id1].name;
if(e.Registrant_type_group__c == NULL)
{
e.Registrant_type_group__c = [select epz.Id from Event_permission_zem__c epz where epz.zimmer_event__c = :e.zimmer_event__c and epz.type__c = 'Event Capacity' and epz.Registrant_Types__c INCLUDES (:s)][0].id;
}
}
}
Any help is appriciated. Thanks in advance.
You need to move the SOQL statements outside of the FOR loop and leverage the Trigger.new as a SET in your query. Take a look a the following documentation:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_patterns_bulk.htm
See if this blog post helps you...
Writing Bulk Triggers for Salesforce.com
Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com
Author: The Salesforce Handbook
hi here is the below syntax for the asynchronous class which handles bulk processing.
this is the example for bulkifying the triggers.
Thank you all for the responses. I will try and let you all know what happened.