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

Inserting Updating Bulk Records through Data Loader...!!!(Based on Before Insert ,Before Update Trigger)
Hi All,
I have two Custom Objects A and B with Master Detail Relationship.We have written one trigger with Before Insert and Before update Trigger for auto populating A field in B Object based on Five conditions .Trigger is working fine.But when we Upload Bulk records of Achievements through Data Loader nearly 40 k Records some are updating the Target Field and some of them are not updating.Some records won't match the conditions thats is fine but some records of Achievements if i update manually it is populating.We checked by reducing the Batch Size also still not resolved.Can any one help on this issue as soon as possible.I am posting the code as well can anyone help me on this trigger to make work for bulk Records also...
trigger populateAfield on ObjectB(before insert,before Update)
{
set<id> userids =new set<id>();
set<id> accids =new set<id>();
set<string> plant=new set<string>();
set<string>rgn=new set<string>();
set<string> compont=new set<string>();
set<integer> Month =new set<integer>();
set<Decimal> invceamt = new set<Decimal>();
Map<id,ObjectA> mpA = new map<id,ObjectA>();
forObjectB ac :trigger.new)
{
/*if(ac.User__c!=Null)
{
userids.add(ac.User__c);
}*/
if(ac.Account__c!=null)
{
accids.add(ac.Account__c);
}
if(ac.Plant__c!=null)
{
plant.add(ac.Plant__c);
}
if(ac.Component__c!=Null)
{
compont.add(ac.Component__c);
}
if(ac.Invoice_Date__c!=null)
{
month.add(ac.Invoice_Date__c.Month());
}
if(ac.Region__c!=null)
{
rgn.add(ac.Region__c);
}
}
List<ObjectA>A = [select id,OwnerId,Name,Account__c,Component__c,Plant__c,Region__c,
Target_Amount__c,Target_Date__c,User_Name__c from A Where Region__c IN:rgn AND CALENDAR_MONTH(Invoice_Date__c) IN :month AND
Account__c IN:accids AND Component__c IN:compont AND Plant__c
IN :plant
//AND User_Name__c IN :userids
];
if(A!=null)
{
for(ObjectA t:A )
{
mpA .put(t.Account__c,t);
system.Debug('@@@@@@@@@@@@@@@@@@@@@@@'+mpA);
}
}
if((mpA .Size()>0))
{
for(ObjectB ach:Trigger.New)
{
if(ach.Account__c!=Null)
{
if(mpA .get(ach.Account__c)!=Null)
{
Integer acmonth=ach.Invoice_Date__c.Month();
Integer tarmonth=mpA .get(ach.Account__c).Invoice_Date__c.Month();
if((ach.Account__c==mpA .get(ach.Account__c).Account__c)&&(ach.Component__c==mpA .get(ach.Account__c).Component__c)&&
(ach.Region__c==mpA .get(ach.Account__c).Region__c)&&(acmonth==tarmonth)&&
(ach.Plant__c==mpA .get(ach.Account__c).Plant__c))
{
ach.Target__c = mpA .get(ach.Account__c).id;
}
}
}
}
}
}
Thanks in advance...!!!
I have two Custom Objects A and B with Master Detail Relationship.We have written one trigger with Before Insert and Before update Trigger for auto populating A field in B Object based on Five conditions .Trigger is working fine.But when we Upload Bulk records of Achievements through Data Loader nearly 40 k Records some are updating the Target Field and some of them are not updating.Some records won't match the conditions thats is fine but some records of Achievements if i update manually it is populating.We checked by reducing the Batch Size also still not resolved.Can any one help on this issue as soon as possible.I am posting the code as well can anyone help me on this trigger to make work for bulk Records also...
trigger populateAfield on ObjectB(before insert,before Update)
{
set<id> userids =new set<id>();
set<id> accids =new set<id>();
set<string> plant=new set<string>();
set<string>rgn=new set<string>();
set<string> compont=new set<string>();
set<integer> Month =new set<integer>();
set<Decimal> invceamt = new set<Decimal>();
Map<id,ObjectA> mpA = new map<id,ObjectA>();
forObjectB ac :trigger.new)
{
/*if(ac.User__c!=Null)
{
userids.add(ac.User__c);
}*/
if(ac.Account__c!=null)
{
accids.add(ac.Account__c);
}
if(ac.Plant__c!=null)
{
plant.add(ac.Plant__c);
}
if(ac.Component__c!=Null)
{
compont.add(ac.Component__c);
}
if(ac.Invoice_Date__c!=null)
{
month.add(ac.Invoice_Date__c.Month());
}
if(ac.Region__c!=null)
{
rgn.add(ac.Region__c);
}
}
List<ObjectA>A = [select id,OwnerId,Name,Account__c,Component__c,Plant__c,Region__c,
Target_Amount__c,Target_Date__c,User_Name__c from A Where Region__c IN:rgn AND CALENDAR_MONTH(Invoice_Date__c) IN :month AND
Account__c IN:accids AND Component__c IN:compont AND Plant__c
IN :plant
//AND User_Name__c IN :userids
];
if(A!=null)
{
for(ObjectA t:A )
{
mpA .put(t.Account__c,t);
system.Debug('@@@@@@@@@@@@@@@@@@@@@@@'+mpA);
}
}
if((mpA .Size()>0))
{
for(ObjectB ach:Trigger.New)
{
if(ach.Account__c!=Null)
{
if(mpA .get(ach.Account__c)!=Null)
{
Integer acmonth=ach.Invoice_Date__c.Month();
Integer tarmonth=mpA .get(ach.Account__c).Invoice_Date__c.Month();
if((ach.Account__c==mpA .get(ach.Account__c).Account__c)&&(ach.Component__c==mpA .get(ach.Account__c).Component__c)&&
(ach.Region__c==mpA .get(ach.Account__c).Region__c)&&(acmonth==tarmonth)&&
(ach.Plant__c==mpA .get(ach.Account__c).Plant__c))
{
ach.Target__c = mpA .get(ach.Account__c).id;
}
}
}
}
}
}
Thanks in advance...!!!
With data load operations what we normally do is actually mute the triggers for a particular user before doing the Data load.You can probably try the same and then later on run a batch job to update the records so that the triggers are executed.
Hope this helps!!!
Thanks,
Chinmay B