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

exception while retrieving user records


I have a query retrieving the userinfo from user in a trigger.


Here i am retrieving a custom field from  user object.

Below is the query: 


String userid= userinfo.getUserId();

User[] userType = [select u.custom__c from User u where u.Id=:userid limit 1];


the exception is:

Apex script unhandled trigger exception by user/organization: 00540000001RUm8/00D300000001EBY caused by: System.Exception: Too many SOQL queries: 21


can anyone whats wrong eith the query to avoid gov limits.


Exception is not for that particular query. Its due to governer limits.

Total number of SOQL queries allowed in one context run of trigger is 20.

And as that query on user is 21 its throwing exception.


so how can we avoid this? because i am not able to pass the ids to set.


Let me know if any soln.



Can you post your code? Difficult to optimize it if we can't see it =)