You need to sign in to do that
Don't have an account?
Afrose Ahamed
AFTER Update fires when record Insert
Hi All,
When i update record only after update firing as expected. But i insert record both after insert and after update firing. Im not sure its due to recursion. But in my org there is no work flow update rule in this object. So im not sure its recursion issue or not. But i tried to add boolean static variable but still the same execution is happening. Please someone help on this to understand better.
Regards,
Afrose Ahamed M.G.
When i update record only after update firing as expected. But i insert record both after insert and after update firing. Im not sure its due to recursion. But in my org there is no work flow update rule in this object. So im not sure its recursion issue or not. But i tried to add boolean static variable but still the same execution is happening. Please someone help on this to understand better.
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 ); } }
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 ); } }
Regards,
Afrose Ahamed M.G.
In your code, below code will execute both insert or update conditions.
If you want run the code seperately then your context variable conditions will be like below.
All Answers
What is the error you were facing?
Thanks!!
Hi @Ankaiah,
Im not facing any errors, Actually when i insert a new record after update trigger also executing. So its taking insert and update DML counts in one transaction. Why After update trigger is occuring when inserting a record here?
Regards,
Afrose Ahamed M.G.
In your code, below code will execute both insert or update conditions.
If you want run the code seperately then your context variable conditions will be like below.
Hi @Ankaiah,
Thanks for your response.
Now i have separated my context variable but still After update operation executin when i insert a record. Actually my logic is same when insert or update happen. but when i insert record its should need to call only After insert operation and when i update record its need to call only After update operation.
trigger ParamsUpdate Obj1__c (after insert, after update ) {
if(trigger.IsAfter && trigger.IsInsert)
{
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){
obj3idlst.add( obj3.Obj4__c);
}
Mylogics.updateparams ( obj4idlst );
}
if(trigger.IsAfter && trigger.Update)
{
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){
obj3idlst.add( obj3.Obj4__c);
}
Mylogics.updateparams ( obj4idlst );
}
}
Hi @Smith Smith 3,
Really sorry, I forget to share my apex class. And my concept obj1 is child for obj2. Obj 3 child for obj4. When obj1 insert or update every obj1 and obj3 child records deleted again it will insert as new record.