function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aaron HillAaron Hill 

Apex Trigger not Working on Bulk Update

I have a trigger to update a related account field on my leads when there is a name match or a match of a third party id. This trigger should fire whenever a lead is created or updated and works perfectly for individual records but does not work when I use the data import wizard to update multiple leads at once. 

My research into this issue tells me that apex triggers by default should fire for bulk records and indeed previous triggers I've written have worked for bulk records so I'm confused about why there's an exeption here. I'll paste my code below. Thank you.
 
trigger updateRelatedAccount on Lead (before update, before insert) { 
    set<string> accNames = new set<string>();
    set<Decimal> accLIDs = new set<Decimal>();
        for(Lead ld : Trigger.New){
        	accNames.add(ld.Company);
            accLIDs.add(ld.Company_ID__c);
        } 
    
    

        list<Account> accs = new list<Account>([Select Id,Name,LinkedIn_Id__c from account where name in :accNames or LinkedIn_Id__c in :accLIDs]); //using WHERE IN
        map<String,id> mapaccs = new map<String,id>();
    	map<Decimal, id> mapids = new map<Decimal, id>();

        for(Account ac : accs){
        	mapaccs.put(ac.Name,ac.Id);
            mapids.put(ac.LinkedIn_Id__c,ac.Id);
        }

        for(Lead lds : Trigger.New){ 
            //you new lead has company id, check if lead has same id
            if (lds.Company_ID__c !=null and mapids.get(lds.Company_ID__c)!=null) { 
                lds.Related_Account__c = mapids.get(lds.Company_ID__c); //if so, copy id
            } else { //if not, search by name
                lds.related_account__c = mapaccs.get(lds.company);
            }
        }
  }

 
Anand_VAnand_V
Hi Aaron,
Did you try to perform bulk update from console? I think there are some rules around Data Import Wizard which might be stopping the trigger from running(in which case it does not mater if it's a single record or bulk).