You need to sign in to do that
Don't have an account?
Afrose Ahamed
how to move transaction into async process when exceeding limit
Hi All,
Greetings of the day!
Below mentioned two lines are exceeding governor limits. I want to change this below mentioned line with condition based. If query rows is below 50000 and DML rows below 10000 then its should be in sync process if above it should be in async process. which is best batch apex or scheduled apex and how i can change the code and how can i wrote batch apex or scheduled apex. Please some one help me on this.
Regards,
Afrose Ahamed M.G.
Greetings of the day!
Below mentioned two lines are exceeding governor limits. I want to change this below mentioned line with condition based. If query rows is below 50000 and DML rows below 10000 then its should be in sync process if above it should be in async process. which is best batch apex or scheduled apex and how i can change the code and how can i wrote batch apex or scheduled apex. Please some one help me on this.
//some times this query exceeding more than 50000 rows and giving an error List<Obj2__c> obj2new = [SELECT id,name,(SELECT name FROM objs1__r) FROM Obj2__c WHERE id in : paramids]; //some times this line exceeding 10000 dml rows and giving an error RecordsManager.InsertAsSystem( paramnewlist );
trigger ParamsUpdate on Obj1__c (after insert, after update ) { if(trigger.IsAfter && (trigger.IsInsert || trigger.IsUpdate)) { List<String> obj2Ids = new List<String>(); for( Obj1__c objs: Trigger.New){ obj2Ids.add ( objs.Obj2__c); } List<Obj3__c> obj3ids = [SELECT id, Obj4__c FROM Obj3__c WHERE obj2__c IN : obj2Ids]; List<String> obj4idlst= new List<String>(); for( Obj3__c obj3 : obj3ids){ obj4idlst.add( obj3.Obj4__c); } MyLogics.updateParams ( obj4idlst ); } }
public with sharing class MyLogics{ public static void updateParams( List<String> obj4idlst ){ Map<String,List<String>> paramsMap = new Map<String,List<String>>(); List<Obj3__c> oldparams = [SELECT id FROM Obj3__c WHERE Obj4__c IN : obj4idlst ]; RecordsManager.DeleteAsSystem( oldparams ); // Delete oldparams; List<Obj4__c> Objs4 = [SELECT id,name,(SELECT id,name,Obj2__c FROM Objs3__r) FROM Obj4__c WHERE id IN : obj4idlst]; List<String> paramids = new List<String>(); for( Obj4__c obj4: Objs4){ for( Obj3__c lst : obj4.Objs3__r){ paramids.add ( lst.Obj2__c ); } } //this query exceeding morethan 50000 rows List<Obj2__c> obj2new = [SELECT id,name,(SELECT name FROM objs1__r) FROM Obj2__c WHERE id in : paramids]; List<String> tempParam = new List<String>(); for( Obj2__c func: obj2new){ for( Obj1__c Param : func.objs1__r ){ tempParam.add ( Param.Name ); } paramsMap.put ( func.Id, tempparam); } List<Obj3__c> paramnewlist = new List<Obj3__c>(); for( Obj4__c lsts: Objs4){ for( Obj3__c FTS : lsts.objs3__r ){ if( paramsMap.get ( FTS.Obj2__c) != null){ for( String parameterName : paramsMap.get ( FTS.Obj2__c )){ paramnewlist.add( new Obj3__c( name=parameterName, Obj4__c=lsts.Id)); } } } } //this line exceeding 10000 dml rows RecordsManager.InsertAsSystem( paramnewlist ); } }
Regards,
Afrose Ahamed M.G.
You can move the parts of the code that are exceeding governor limits to a batch apex or scheduled apex class. Here's how you can modify your code:
Here is the trigger My logics class
Hi @Shri Raj,
Thanks for your response,
Great! but here i noticed in my trigger is not querying more records. In my apex class querying more records. Below is the line that is querying more records.how can i change that based on records retrived. Like here i need to aggregate result or what? Can you please help explain and how we can query based on count.
Regards,
Afrose Ahamed M.G.
If we query more than 50000 rows mean it will show error in sync process.then how the condition will check here? if its exceed the limit the same error occurs right.? Can you please help to understand more.
Regards,
Afrose Ahamed M.G.