+ Start a Discussion
Shawn Reichner 29Shawn Reichner 29 

SOQL 101 Error on Trigger

Hello Awesome Devs,

I have the followign Trigger that has ben working without error, but now that I have an need to update all of our Account records in our Org, I am hitting SOQL 101 errors a plenty.  Anyone have any thoughts on how to bulkify this code even more to stop these errors? 

Thank you for any help you are able to provide.....

Shawn

Trigger code - 
trigger SetAccountActiveOnContactRecord on Account (after insert, after update) {

    
    List<Contact> consToUpdate = new List<Contact>();
    set<id> accIds = new set<id>();
    For(Account a : Trigger.new){
        If(a.Status__c == 'Active'){
           accIds.add(a.id);
        }
    }
  
   List<Contact> consToAdd = [SELECT ID, Account_Active__c, AMP_Notification_Types__c, Contact_Types__c FROM Contact WHERE AccountId = : accIds  AND Account_Active__c != True AND 
                                       (AMP_Notification_Types__c INCLUDES('Technical','Billing','Account') OR Contact_Types__c INCLUDES('Technical'))];
            
            If(consToAdd.size()>0){
            For(Contact c : consToAdd){
                
                c.Account_Active__c = True;
                consToUpdate.add(c);
            
            }
            }
    
    if(consToUpdate.size()>0){
        update consToUpdate;
    }
    
    
}

 
VamsiVamsi
Hi,

Change this AccountId = : accIds 
to 
AccountId IN : accIds 
Shawn Reichner 29Shawn Reichner 29
I made the change, but am still receiving the SOQL 101 errors on this trigger.  Thanks for the thought, any other ideas from anyone to help resolve this issue? 
VamsiVamsi
How many records are you trying to update ?
Shawn Reichner 29Shawn Reichner 29
10k plus.  So my trigger is bulkified?  I thought it was, but am struggling to identify why?