Wondering why for the below code I am getting Field Integrity Exception error. Have 2 Lookup fields to Opportunity in Opportunity Object. ParentOpportunity and UltimateParentOpportunity. Trying to update the Ultimate as the current Opportunity when a condition satisfies.
Apex Code Sample
List<Opportunity> optyList = [Select Id, Name,ParentOpportunity__c, UltimateParentOpportunity__c
from Opportunity
LIMIT 10]; // 'UltimateParentOpportunity__c' and 'ParentOppoertunity__c' are Lookups to Opportunity object
for(Opportunity opp: optyList){
opp.UltimateParentOpportunity__c = opp.Id;
}
update optyList;
System.debug(' optyList after-- '+optyList);