function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marc GauthierMarc Gauthier 

triggers on 2 objects recursively - Error: The record you were editing was modified ...

Hi,

 

I have 2 objects A and B which i am trying to synchronize.i.e updating or inserting owner field in object A will sync owner record in B. So i have 1 trigger each on each object which updates the records. The issue is, these triggers will keep running recursively as everytime an appointmet is updated the event is also updated and the triggers keep firing. I used the following solution which made the sync between A  &  B  object work .

 

Trigger on A:

 

trigger klm on A (after insert, after update)
{
if (klm.stateA == false) //static boolean variable initialised to false
{
klm.stateA= true;
new klm(trigger.old, trigger.new).execute();
klm.stateA=false;
}
}

 

Initialized static boolean variables in class lmn and pqr to false

 

Trigger on B:

trigger pqr on B (after insert, after update) 
{
if (pqr .stateB == false) //static boolean variable initialised to false
{
pqr .stateB= true; 
new pqr (trigger.old, trigger.new).execute();
pqr .stateB=false;
}
}

 

The code works !!!, but the problem is that when I try to update the record , only sometimes it throws the following error:

" The record you were editing was modified by XXX user during the edit sesssion" 

At first I found the problem is only when i try to update or insert using "Inline" editing but later found that the problem was existing even when I tried to click edit and save the record. I am not able to uderstand why this kind of error occurs.

Please help me if you are familiar with this kind of error. 

 

Thanks,

Marc

IspitaIspita

Hi Marc,

Are there any other constructs like work flows which are updating these two objects, my assumption since you are not getting this error regularly is that is certain condition some other trigger or Workflow rule is also updating or changing the records concerned hence you are encountering this issue.

Probably apart from the flags you can also put a check to fire the triggers only when the "Owner" fields are changed.

Hope thisn helps...

UVUV

This is general error mostly poeple see and you may see this error if  any other user was working on that record your trigger was trying to update..Keep in mind that at a time only one user can modify the record.