• kkumar011985
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    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

 

Hi,

 

I am getting too many code statements:200001 while inserting the Records on the Custom Object.on the custom object one trigger is there.i am calling one class when the criteria is met in the Trigger.This is mmy class and Trigger code..please help on this.

 

trigger updateToUser on Export_Object__c (after insert,after update)
{
for(Export_Object__c e: Trigger.New)
{
if(e.Alias__c=='test'){
getUnupdatedUsers gu = new getUnupdatedUsers();
gu.mymethod();
}
}

}

 

class:

 


public class getUnupdatedUsers
{
List<Export_Object__c> eo_list = new List<Export_Object__c>();
set<String> eoid = new set<String>();

List<User> user_list = new List<User>();
List<User> updatelist = new List<user>();
List<User> updatefailedlist = new List<User>();

public void mymethod()
{
eo_list = [select id,Alias__c,City__c,Company__c,Country_Region__c,Department__c,FirstName__c,Mobile__c,state__c,Address__c,Telephone__c,Title__c from Export_Object__c];
for(Export_Object__c e: eo_list)
{
if(e.Alias__c!=null)
eoid.add(e.Alias__c);
}
user_list = [select id,adid__c from user where adid__c in: eoid];


for(Export_Object__c e: eo_list)
{
for(User u:User_List)
{
if(u.ADID__c == e.Alias__c)
{
if(e.City__c!=null)
u.City = e.City__c;
if(e.Company__c!=null)
u.CompanyName = e.Company__c;
if(e.Country_Region__c!=null)
u.Country = e.Country_Region__c;
if(e.Department__c!=null)
u.Department = e.Department__c;
if(e.FirstName__c!=null)
u.FirstName = e.FirstName__c;
if(e.Mobile__c!=null)
u.MobilePhone = e.Mobile__c;
if(e.state__c!=null)
u.State = e.state__c;
if(e.Address__c!=null)
u.Street = e.Address__c;
if(e.Telephone__c!=null)
u.phone = e.Telephone__c;
if(e.Title__c!=null)
u.Title = e.Title__c;
//u.available__c = true;
updatelist.add(u);
}

}
}
update updatelist;
updatefailedlist = [select id,ADID__c,name,email from user where id !=: updatelist];
system.debug('updatefailedlist '+updatefailedlist.size());
if(updatefailedlist.size()>0){
system.debug('mismatchlist size');
mismatchlist();
}
}

public void mismatchlist()
{
string header = 'Name , ADID, Email \n';
String finalstr = header;
for(user eo :updatefailedlist)
{
string recordString = '"'+eo.name+'","'+eo.adid__c+'","'+eo.email+'"\n';
finalstr = finalstr +recordString;
}
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setFileName('Employee.csv');
attach.Body = Blob.valueOf(finalstr);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'work@gmail.com'};
String subject ='Export CSV';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setHtmlBody('Export CSV ');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
}

 

Hi,

I have a problem with the Data Loader.
I am trying to insert 5000 records from the Data loader to One Custom Object and on the Custom Object I have written a Trigger.

My Scenario is, In the Trigger I have written a code to update User Object Fields from the custom object. Here I want to send an email from the Trigger those who are not updated in the User Object.
So I want to generate single email with that list but I am getting 25 emails. I observed on the Data loader Per each 200 inserts I am getting one email like for 5000 records finally i am getting 25 emails.

I have increased the batch size in data loader but of no use and checked the Bulk API option also and set the Batch size as 2000.Still i am getting an Email for every 200 insertions.

Please help me what is the solution for this.

Regards,
Narendra

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

 

Hi,

 

I am getting too many code statements:200001 while inserting the Records on the Custom Object.on the custom object one trigger is there.i am calling one class when the criteria is met in the Trigger.This is mmy class and Trigger code..please help on this.

 

trigger updateToUser on Export_Object__c (after insert,after update)
{
for(Export_Object__c e: Trigger.New)
{
if(e.Alias__c=='test'){
getUnupdatedUsers gu = new getUnupdatedUsers();
gu.mymethod();
}
}

}

 

class:

 


public class getUnupdatedUsers
{
List<Export_Object__c> eo_list = new List<Export_Object__c>();
set<String> eoid = new set<String>();

List<User> user_list = new List<User>();
List<User> updatelist = new List<user>();
List<User> updatefailedlist = new List<User>();

public void mymethod()
{
eo_list = [select id,Alias__c,City__c,Company__c,Country_Region__c,Department__c,FirstName__c,Mobile__c,state__c,Address__c,Telephone__c,Title__c from Export_Object__c];
for(Export_Object__c e: eo_list)
{
if(e.Alias__c!=null)
eoid.add(e.Alias__c);
}
user_list = [select id,adid__c from user where adid__c in: eoid];


for(Export_Object__c e: eo_list)
{
for(User u:User_List)
{
if(u.ADID__c == e.Alias__c)
{
if(e.City__c!=null)
u.City = e.City__c;
if(e.Company__c!=null)
u.CompanyName = e.Company__c;
if(e.Country_Region__c!=null)
u.Country = e.Country_Region__c;
if(e.Department__c!=null)
u.Department = e.Department__c;
if(e.FirstName__c!=null)
u.FirstName = e.FirstName__c;
if(e.Mobile__c!=null)
u.MobilePhone = e.Mobile__c;
if(e.state__c!=null)
u.State = e.state__c;
if(e.Address__c!=null)
u.Street = e.Address__c;
if(e.Telephone__c!=null)
u.phone = e.Telephone__c;
if(e.Title__c!=null)
u.Title = e.Title__c;
//u.available__c = true;
updatelist.add(u);
}

}
}
update updatelist;
updatefailedlist = [select id,ADID__c,name,email from user where id !=: updatelist];
system.debug('updatefailedlist '+updatefailedlist.size());
if(updatefailedlist.size()>0){
system.debug('mismatchlist size');
mismatchlist();
}
}

public void mismatchlist()
{
string header = 'Name , ADID, Email \n';
String finalstr = header;
for(user eo :updatefailedlist)
{
string recordString = '"'+eo.name+'","'+eo.adid__c+'","'+eo.email+'"\n';
finalstr = finalstr +recordString;
}
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setFileName('Employee.csv');
attach.Body = Blob.valueOf(finalstr);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'work@gmail.com'};
String subject ='Export CSV';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setHtmlBody('Export CSV ');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{attach});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
}

 

Hi,

I have a problem with the Data Loader.
I am trying to insert 5000 records from the Data loader to One Custom Object and on the Custom Object I have written a Trigger.

My Scenario is, In the Trigger I have written a code to update User Object Fields from the custom object. Here I want to send an email from the Trigger those who are not updated in the User Object.
So I want to generate single email with that list but I am getting 25 emails. I observed on the Data loader Per each 200 inserts I am getting one email like for 5000 records finally i am getting 25 emails.

I have increased the batch size in data loader but of no use and checked the Bulk API option also and set the Batch size as 2000.Still i am getting an Email for every 200 insertions.

Please help me what is the solution for this.

Regards,
Narendra