You need to sign in to do that
Don't have an account?

ERROR : Too many SOQL queries: 101
HI,
I'm getting error"Too many SOQL queries: 101" in line User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ]; of code below :-
I have highlighted the line below.
//Method added for Sending AFD to Siebel
if(trigger.isBefore && trigger.isUpdate){
Set<String> caOwnerId = new Set<String>();
Map<Id,User> ownerRole = new Map<Id,User>();
String s_profile = null; //Addition for Defect 13928
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name from User where id = :caOwnerId]);
}
User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ];
s_profile = user1.Profile.Name;
for(Credit_Approval__c ca:trigger.new){
if(OwnerRole.get(ca.OwnerId)!=null && !'GE Integration User'.equalsIgnoreCase(s_profile)){
//if(OwnerRole.get(ca.OwnerId)!=null{
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Flow';
}
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& !OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Structured';
}
}
}
}
}
I'm getting error"Too many SOQL queries: 101" in line User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ]; of code below :-
I have highlighted the line below.
//Method added for Sending AFD to Siebel
if(trigger.isBefore && trigger.isUpdate){
Set<String> caOwnerId = new Set<String>();
Map<Id,User> ownerRole = new Map<Id,User>();
String s_profile = null; //Addition for Defect 13928
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name from User where id = :caOwnerId]);
}
User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ];
s_profile = user1.Profile.Name;
for(Credit_Approval__c ca:trigger.new){
if(OwnerRole.get(ca.OwnerId)!=null && !'GE Integration User'.equalsIgnoreCase(s_profile)){
//if(OwnerRole.get(ca.OwnerId)!=null{
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Flow';
}
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& !OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Structured';
}
}
}
}
}
Check all the trigger related to Credit_Approval__c object all event it may having any query in loop,
and also improve your code use minimum query in the same context it could helpful you,
ex: you write the two query insted of one query
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
caOwnerId.add(UserInfo.getUserId())
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name,Profile.Name from User where id = :caOwnerId]);
}
User user1 = ownerRole.get(UserInfo.getUserId() );
Thanks
Satya
All Answers
Ideally that should be placed out of the loop.
You may gather all the User ID's in a Set and then issue just one soql query to get all the data.
Regards,
Satish Kumar
Thanks in Advance!!!
Check all the trigger related to Credit_Approval__c object all event it may having any query in loop,
and also improve your code use minimum query in the same context it could helpful you,
ex: you write the two query insted of one query
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
caOwnerId.add(UserInfo.getUserId())
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name,Profile.Name from User where id = :caOwnerId]);
}
User user1 = ownerRole.get(UserInfo.getUserId() );
Thanks
Satya
I'm facing similar issue :-
Highlighted the line i'm getting Too many SOQL queries: 101
if(trigger.isAfter){
if(caids.size()>0){
Set<Id> RelCreditApprovalId= new Set<Id>();
for(credit_approval__c ca:trigger.new){
if(caids.contains(ca.id)){
if(ca.Credit_Line_Id__c!=null){
system.debug('Credit Line Id (LOC): '+ca.Credit_Line_Id__c);
RelCreditApprovalId.add(ca.Credit_Line_Id__c);
}
}
}
List<Credit_Approval__c> RelCreditApprovalList= [select Id,Application_Type__c,Credit_Line_ID__c,Submittal_Status__c,Approved_Amount__c,Approved_Amount_With_Tolerance__c,LOC_Adjustment_Amount__c, Risk_Decision__c,Amount_Approved_Remaining__c,
Credit_Line_ID__r.Submittal_Status__c,Credit_Line_ID__r.Approved_Amount__c,Credit_Line_ID__r.Approved_Amount_With_Tolerance__c,Credit_Line_ID__r.Risk_Decision__c,Opportunity__c
from Credit_Approval__c where Id in :RelCreditApprovalId];
if(RelCreditApprovalList!=null && RelCreditApprovalList.size()>0){
try{
update RelCreditApprovalList;
}catch(DMLException e){
system.debug('/nDML Exception : '+e.getmessage());
}
}
}
}