I have Opportunity-lookup field on Opportunity (self),


  1. Opportunity A if select Opportunity B using lookup then Opportunity B's same lookup field automatically populate with Opportunity A.

I tried to achieve this using trigger - before insert/update but its failing as:

System.DmlException: Update failed. First exception on row 0 with id 006G000000DHaBlIAL; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 006G000000DHaBl) is currently in trigger Oppy_before_INSUPD, therefore it cannot recursively update itself: []  

1 Answer 1


When you are in before insert trigger you can't reference the record being inserted as it hasn't been inserted yet. There is no Id to be referenced.

So when Opportunity A is being inserted, it can have a reference to Opportunity B (assuming it isn't being inserted in the same transaction) as it will have an Id and be in the database.

Until Opportunity A has been inserted there is nothing for Opportunity B to reference.

You could potentially use an after update trigger to update the reference from Opportunity B to point back to Opportunity A. Be careful here with the potential to create an update loop if you keep trying to update the related records reference.

See also Why do my Apex Triggers throw the error SELF_REFERENCE_FROM_TRIGGER?


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .