+ Start a Discussion
Rst123Rst123 

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';
            }       
          }  
    }
  }


}



Can you please help me out on this to acheive this.
Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr
Hi
The user query should be bulkified in trigger. Check following trigger best practices link this will be helpful to you.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bestpract.htm
Rst123Rst123
Can you help me sort out the problem...

I have highlighted the line where i'm getting Too many soql Error 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());
                 }
             }
        }       
     }