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
Sukhdeep SinghSukhdeep Singh 

Getting "Too many SOQL queries" Exception in trigger

Hi,

I need to check the "Assign using active assignment rule" check box field & change status to 'open' at Lead update But getting error "System.LimitException: Too many SOQL queries: 101"
Please suggest,

Thanks,

The code is below


trigger AssignLeadFromTimeOutQ on Lead (after update) {

    List<Lead> ls = new List<Lead>();
    Lead tempLead = Trigger.new[0];
        if (tempLead.OwnerId == '00P40000001l62pEAA' && UserInfo.getUserId() == '00570000001PNMtAAO') {
            ls.add(new Lead(id = tempLead.id, status = 'Open'));
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule = true;         
            Database.update(ls, dmo);   
          }
}
Bhanu MaheshBhanu Mahesh
Hi Sukhdeep,

Try below code
trigger AssignLeadFromTimeOutQ on Lead (after update) {
	List<Lead> ls = new List<Lead>();
	Lead tempLead = Trigger.new[0];
	for (Lead l : Trigger.new){
		if (l.OwnerId == '00P40000001l62pEAA' && UserInfo.getUserId() == '00570000001PNMtAAO'){
			ls.add(new Lead(id = l.id, status = 'Open'));
		}
	}
	Database.DMLOptions dmo = new Database.DMLOptions();
	dmo.assignmentRuleHeader.useDefaultRule = true;         
	Database.update(ls, dmo);
}

Also refre the below links

http://salesforce.stackexchange.com/questions/13651/lead-assignment-rule-in-a-trigger

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008saZIAQ


https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yEWIAY
Regards,
Bhanu Mahesh

Mark it as "SOLVED" if your query is  answered
Sukhdeep SinghSukhdeep Singh

Hi Bhanu,

Thanks for your reply, I tried the code but still getting the same error.

Thanks,