• phamleDev
  • NEWBIE
  • 5 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hi,

 

I have written a trigger to update user manager field based on the custom object.

There is no relationship between these two objects. Only thing is that common field is there in these 2 objects.

 

for 10 to 20 records manager field was getting update fine but when I was trying to insert 4000 records I'm getting an exception,,

 

Update failed. First exception on row 0 with id 0014000000b5gNsAAI; first error: CIRCULAR_DEPENDENCY,you cannot set hierarchy field to point to itself or a child record:[]

 

Here is the code,

 

 

trigger updateToUser on Export_Object__c (after insert)
{
    List<Export_Object__c> deleteexportobject = new List<Export_Object__c>(); 
        Set<String> eoid = new Set<String>();
        for(Export_Object__c e: Trigger.New)
        {
            if(e.adid__c!=null)
            {
                eoid.add(e.adid__c);
            }
        }
        
        List<User> user_list = [select id,adid__c,name from user where adid__c in: eoid];
        
        Transient Map<string,string> mapRecords = new Map<string,string>();
        
        List<User> user_list1 = [select id,adid__c,name from user];
        
        for(User u:User_List1)
        {
          mapRecords.put(u.Name,u.id);
        }
        
         system.debug('*****'+mapRecords);
        List<User> updatelist = new List<user>();
        
        for(Export_Object__c e: Trigger.New)
        {
            for(User u:User_List)
            {
                if(e.Manager__c!=null)
                {                            
                    try
                    {                         
                        u.managerId = mapRecords.get(e.Manager__c);
                    }
                    catch(exception ee)
                    {
                        system.debug('tusssssssssssssssss');                    
                    }
                }
                updatelist.add(u);
            }
            
        }
        update updatelist;

 

 

Please help me out where I am doing the mistake

 

THank you