Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

Scenario:

  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: []  
share|improve this question
    
Can you post your trigger? –  highfive Apr 4 at 7:09

1 Answer 1

up vote 3 down vote accepted

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?

share|improve this answer
    
Hi All I have same problem.Can you please click this link salesforce.stackexchange.com/questions/42537/… See the log I a have got same issue. –  Ramesh Jul 11 at 4:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.