You need to sign in to do that
Don't have an account?
giri rockzzzz
How to create bulkified trigger???
How to create bulkified trigger???can anyone give me sample example
????
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
How to create bulkified trigger???can anyone give me sample example
????
Below are few suggestions,
Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. When a batch of records initiates Apex, a single instance of that Apex code is executed, but it needs to handle all of the records in that given batch. For example, a trigger could be invoked by an Force.com Web Services API call that inserted a batch of records. So if a batch of records invokes the the same Apex code, all of those records need to be processed as a bulk, in order to write scalable code and avoid hitting governor limits.
Here is an example of poorly written code that only handles one record:
trigger accountTestTrggr on Account (before insert, before update) {
//This only handles the first record in the Trigger.new collection
//But if more than 1 Account initiated this trigger, those additional records
//will not be processed
Account acct = Trigger.new[0];
List<Contact> contacts = [select id, salutation, firstname, lastname, email
from Contact where accountId = :acct.Id];
}
The issue is that only one Account record is handled because the code explicitly accesses only the first record in the Trigger.new collection by using the syntax Trigger.new[0]. Instead, the trigger should properly handle the entire collection of Accounts in the Trigger.new collection.
Here is a sample of how to handle all incoming records:
trigger accountTestTrggr on Account (before insert, before update) {
List<String> accountNames = new List<String>{};
//Loop through all records in the Trigger.new collection
for(Account a: Trigger.new){
//Concatenate the Name and billingState into the Description field
a.Description = a.Name + ':' + a.BillingState
}
}
For more examples, go through the URL http://sfdc.arrowpointe.com/2008/09/13/bulkifying-a-trigger-an-example/
Hope this helps.
Here is an example of poorly written code that only handles one record:
01
trigger accountTestTrggr on Account (before
insert
, before
update
) {
02
03
//This only handles the first record in the Trigger.new collection
04
//But if more than 1 Account initiated this trigger, those additional records
05
//will not be processed
06
Account acct
=
Trigger.
new
[
0
];
07
List
<Contact
>
contacts
=
[
select
id, salutation, firstname, lastname, email
08
from
Contact
where
accountId
=
:acct.Id];
09
10
}
The issue is that only one Account record is handled because the code explicitly accesses only the first record in the
Trigger.new
collection by using the syntaxTrigger.new[0]
. Instead, the trigger should properly handle the entire collection of Accounts in theTrigger.new
collection.Here is a sample of how to handle all incoming records:
01
trigger accountTestTrggr on Account (before
insert
, before
update
) {
02
03
List
<
String
>
accountNames
=
new
List
<
String
>
{};
04
05
//Loop through all records in the Trigger.new collection
06
for
(Account a: Trigger.
new
){
07
//Concatenate the Name and billingState into the Description field
08
a.Description
=
a.Name +
':'
+ a.BillingState
09
}
10
11
}