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

After Insert Trigger is not firing for Bulk inserting?
Hi All,
I created one trigger (after insert) for my custom object. If i am inserting single record the trigger is firing, but when i am inserting bulk records using DataLoader the trigger is firing only onec? Plz any one help.....
Thanks,
Aswath.
The trigger is supposed to fire only once, however Trigger.new (or .old) will be an array with multiple entries. So, you have to write your trigger to handle all the entries that there might be in the arrays.
If you already knew that, and have taken that into account, post your code.
Best, Steve.
No matter how many items are in Trigger.new, you will only be setting and resetting, and resetting, etc. myatd[0] and myatd[1].
So, Adet and svpln will only ever contain one record.
I'd say just make them lists and change your query to "in", however your loops would be creating MxN payment records which may or may not be what you intend.
Hi Aswath, I guess the problem might be in this line
which will alwaays give you only two records, that to you are using myatd in both the queries. check it once. if your business goal still the same. then
you migt want to use Trigger ' Map '
On the bulk if the forloop consists of different items then you might want to use it like myatd[i] =...; i++;
Hi,
Thanks for reply, the problem is trigger is not firing every time when a record is inserting. It is firing only for the last record?
Trigger will only fire once. Whatever the bulk handling we have to handle inside the trigger using Map and In condintion in queries. i will give you an example see it might be useful
Map<Id, Contact> contactMap = new Map<Id, Contact>();
for(Integer i = 0; i < Trigger.new.size(); i++)
{
contactMap.put(Trigger.new[i].Id, Trigger.new[i]);
}
List<Contact> lstContact = [Select Name, Id From Contact where Id in : contactMap.keyset()];
for(Integer i=0; i < lstContact.size(); i++)
{
//do changes
}
Hi,
Thanks for ur reply, ur code is working fine but its creating duplicates. Here i will explain the criteria :
Thanks,
Aswath.
Use this to prevent duplicates
Map<Id, Contact> contactMap = new Map<Id, Contact>();
for(Integer i = 0; i < Trigger.new.size(); i++)
{
if(!contactMap.containsKey(Trigger.new[i].Id))
{
contactMap.put(Trigger.new[i].Id, Trigger.new[i]);
}
}
List<Contact> lstContact = [Select Name, Id From Contact where Id in : contactMap.keyset()];
for(Integer i=0; i < lstContact.size(); i++)
{
//do changes
}
BESv2 and Srinivas_v2 both are me only:)
Hi Srinivas,
Thanks for ur reply still its not working, for 1st subject visit 5 payments and for 2nd subject visit 5 payments total 10 payments created.
Hi Srinivas,
Thanks for ur reply, i understood ur logic, now i am getting an error in DataLoader 'SObject row doesn't allow errors'. I will check it & get back to u soon.....
Thanks,
Aswath.