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
Arun KArun K 

Too many soql queries

I am running into Too many SOQL queries error..

I know that there is soql inside for loop which is causing the problem.

How to change So that I cannot get "Too many SOQL queries"

 

 

 

public with sharing class Create_pass {
public list<user> usr;
public void create_password() {
List<User> userList = new List<User>();

userList = [SELECT Id,alias,Email,Territory_Id__c,Pass__c,title from User  ];
for (User u : userList)
{
System.setPassword(u.Id,u.Territory_Id__c);
System.debug('DONE: '+ u.Id);

}

}

}

levaleva

Couple of questions 

 

1. How often do you call this class( create_password method) ?

2. Does it really need to go through all the users each run?

 

Try adding the where clause to the select. Only pick users without password, or even better only users you are working on right now  

Naveen NelavelliNaveen Nelavelli

you might have enabled readOnly property of <apex:page> tag,which will block DML operations and gives the error "Too Many SOQL queries" even though your using one soql query.

so remove readonly from page tag and try

Arun KArun K

No Iam not using readonly property