+ Start a Discussion
bikla78bikla78 

Before Update SOQL query strange exeception

I a getting a strange error. I am performing insert using the apex dataloader. However, I am receiving a before update exception? Does anyone now why an update exception would show up when I am inserting new records?

 

 

Event_To_Cand_Status: execution of BeforeUpdate

caused by: System.Exception: Too many SOQL queries: 21

Class.Event_WorkFlow_Manager.UpdateCandidateStatus: line 4, column 19
Trigger.Event_To_Cand_Status: line 2, column 1

jeffdonthemic2jeffdonthemic2

Just wondering out loud here, but does your insert fire off other triggers that cause existing records to be updated?

Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com 

bikla78bikla78

yes. i have a trigger that does a before insert or an update. When a event_type__c is a certain value, it updates a field in the candidate object. I kept getting soql governor limit errors so I was uploading 8 records at a time using the dataloader for the qualified profile value. As soon as I uploaded 8 records for the qualified resume value, i get this error:

 

BODY{font-family:monospace;}

Apex script unhandled trigger exception by user/organization: 00530000000cnEV/00D300000000KZt

Event_To_Cand_Status: execution of BeforeUpdate

caused by: System.Exception: Too many SOQL queries: 21

Class.Event_WorkFlow_Manager.UpdateCandidateStatus: line 4, column 19
Trigger.Event_To_Cand_Status: line 2, column 1

 

 

 

 

trigger Event_To_Cand_Status on Event (before update) {

Event_WorkFlow_Manager.UpdateCandidateStatus(trigger.new);
}
public class Event_WorkFlow_Manager 

   {

   public static void UpdateCandidateStatus(Event[] EvRec) {

     Profile PR = [Select Name from Profile where Id = '00e60000000updM'];

     for (Event a:EvRec) 

            {

         if (a.Subject != 'Sales Meeting' && a.type ==null)

         {  

    //Profile PR = [Select Name from Profile where Id = :a.CreatedBy.ProfileId];

      

      Integer i = [select count() from SFDC_Candidate__c where Id = :a.WhatId];

        if (PR.Name == 'DLC_Recruit_Test' && a.WhatId != null && i > 0) {

           SFDC_Candidate__c cand = [

           select Id, Contact__c, Name, (Select Id From Events where Id = :a.Id)

           from SFDC_Candidate__c

           where Id = :a.WhatId

         ];



         // Offer Accepted workflow method to update Candidate Status



          if (a.Event_Type__c == '1 - Qualified Profile') {

                a.subject = 'Qualified Profile';

                cand.Candidate_Status__c = 'Qualified';

                cand.Candidate_Withdrew__c = a.Candidate_Withdrew__c; 

                cand.Start_Date_Current_Company__c = a.Start_Date__c;

               cand.Candidate_Rejected__c = a.Candidate_Rejected__c ;

               cand.Offer_Not_Extended__c= a.Offer_Not_Extended__c;

               cand.Offer_Declined__c = a.Offer_Declined__c ;

               cand.Fall_Off__c = a.Fall_Off__c;

           try {

             update cand;

             //system.debug('Did Candidate Update!');

           }

           catch (System.DmlException e) {

             system.debug(e.getMessage());

           }

         }

           if (a.Event_Type__c == '2 - Qualified Resume') {

           a.subject = 'Qualified Resume';

           cand.Candidate_Status__c = 'Qualified';

           cand.Candidate_Withdrew__c = a.Candidate_Withdrew__c; 

                cand.Start_Date_Current_Company__c = a.Start_Date__c;

               cand.Candidate_Rejected__c = a.Candidate_Rejected__c ;

               cand.Offer_Not_Extended__c= a.Offer_Not_Extended__c;

               cand.Offer_Declined__c = a.Offer_Declined__c ;

               cand.Fall_Off__c = a.Fall_Off__c;

           try {

             update cand;

             //system.debug('Did Candidate Update!');

           }

           catch (System.DmlException e) {

             system.debug(e.getMessage());

           }  

           

         }