You need to sign in to do that
Don't have an account?
Akash
Bulk DML Issue with Trigger (with high importance)
Hi
I am facing a serious Issue with Trigger Bulk Data Manipulation. I need to insert & delete in bulk with the help of a trigger.
but the problem is that trigger having limit to process 100 DML records. I have tried it using a class & then used the class method in trigger but no success. if anybody did bulk insertion,deletion of more than 100 records through trigger then plz help me out.
its urgent ...
regards,
Akash.....salesforce.com(Developer)
I am facing a serious Issue with Trigger Bulk Data Manipulation. I need to insert & delete in bulk with the help of a trigger.
but the problem is that trigger having limit to process 100 DML records. I have tried it using a class & then used the class method in trigger but no success. if anybody did bulk insertion,deletion of more than 100 records through trigger then plz help me out.
its urgent ...
regards,
Akash.....salesforce.com(Developer)
What is your use case? What are you trying to do?
trigger SessionCapacitychange on Session__c (after update)
{
if (Trigger.isAfter && Trigger.isUpdate)
{
List<Wait_listed_Registrant__c> WaitLst = new List<Wait_listed_Registrant__c>();
List<Wait_listed_Registrant__c> WaitLstdelete = new List<Wait_listed_Registrant__c>();
List <Session_Attendance__c> sessAttdList = new List <Session_Attendance__c>() ;
List<Wait_listed_Registrant__c> delWaitLstdelete = new List<Wait_listed_Registrant__c>();
List<Session_Attendance__c> insertsessAttdList = new List <Session_Attendance__c>() ;
List<Session__c> sessList = new List <Session__c>() ;
List<Id> SessId = new List<Id>();
for(Session__c Sess : Trigger.new)
{
if(Sess.Capacity__c > Trigger.oldMap.get(Sess.Id).Capacity__c)
{
SessId.add(Sess.Id);
}
}
WaitLst = [select Id,Registration__c from Wait_listed_Registrant__c where Session__c in:SessId order by CreatedById DESC];
for(Session__c Sessn : Trigger.new)
{
double balancesize = Sessn.Balance__c;
//system.debug('balancesize.....'+ balancesize);
Integer loopCount = balancesize.intValue();
//system.debug('balancesize------------------------------------------------->>'+balancesize);
if(balancesize>WaitLst.Size())
{
loopCount = WaitLst.Size();
}
// system.debug('WaitLst[1].Registration__c'+WaitLst[1].Registration__c);
Integer SessionMovedCount =0; // system.debug('WaitLst[0].Registration__c'+WaitLst[0].Registration__c);
for(Integer i=0;i<loopCount;i++)
{
system.debug('values.....'+ balancesize);
if( WaitLst!=null && WaitLst.Size()>0 )
{
Session_Attendance__c s = new Session_Attendance__c();
s.Registration__c = WaitLst[i].Registration__c;
s.Session__c= Sessn.Id;
s.Status__c = 'Registered' ;
SessionMovedCount = SessionMovedCount +1;
sessAttdList.add(s);
WaitLstdelete.add(WaitLst[i]);
}
else if(WaitLst==null && WaitLst.Size()<=0)
{
system.debug('WaitList is empty');
}
}
//system.debug('values...........'+sessAttdList);
if ( sessAttdList.size() > 0 )
insertsessAttdList = sessAttdList;
if(WaitLstdelete.size() > 0 )
delWaitLstdelete = WaitLstdelete;
if(insertsessAttdList.size() > 0 )
{
Session__c s = new Session__c(Id= Sessn.Id);
Double value = 0;
if(s.Used__c!=null)
{
value = s.Used__c;
}
value = value + insertsessAttdList.Size();
s.Used__c = value;
sessList.add(s);
}
}
insert insertsessAttdList;
delete delWaitLstdelete;
update sessList;
}
}
This is my Trigger. As you can see that this Trigger will fire on update of my custom Object.
Session__c Object having two Child Objects ---- Session_Attendance__c & Wait_listed_Registrant__c
If i change the capacity of Session then according to balance it will Delete the Waitlist records & according to that it will insert same number of records in SessionAtteendence Object.
The trigger work fine if waitlist got less then 50 records...means total number of DML records processed are less then 100
But if waitlist got more then 50 records it throw an exception...... TOO MANY DML ROWS
like if waitlist got 60 records
it will show ....TOO MANY DML ROWS:120 ( 60 for insert + 60 for delete)
i have followed every rule of best Practices.. please have a look at the code & let me know how to solve this issue.
i have tried it through class & used tht function in class , i tried web service.. but it did nt work
Help needed
Regards;
AKash (Salesforce.com Developer)
There is a feature coming out called scheduled batch and that is what you would need to use to support your use case.
For now you can check where you are at before each DML statement and if you are nearing the limit you can bypass your code.
ie, do the insert but not the delete, and update.
This is not ideal but your users will have a better experience.
Then have an outside process go and grab all the non-processed stuff and clean it up.
Batch processing is what you need and this is a feature that will be out soon.