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
KidNikiKidNiki 

Need help with new trigger not working..old one still fires?

Okay we have an external program that makes a soap connection and then updates the Account Object.  We were getting the

 


System.Exception: Too many SOQL queries: 101 error

 

So I changed the code to be bulk and use a map.  Anyway, I have the new code in Production and we are still getting this error, on the same line accessing the same outside class method. My code does everything in the trigger and doesn't even access the method anymore, beyond that the line number it says the error is on is a comment line in my trigger.  I have been messing with this for about a week... HELP!!!

 

 

Also, I have pushed this to production twice and it is valid and active.

 

Thank you!

 

 

 

 


Starz26Starz26

Please post some code. Unless this is a know bug you will never get a response without some code to put it in context...

KidNikiKidNiki

 

here is the current code, I blew the rest away... as far as I know

 

trigger AccountUpdateState on Account (before update, before insert) 
{
/* 
This trigger runs on insert or update to the account object.  It checks to see if the Billingstate has a value and that the TerritoryState Name (reference) is not equal to it if
that is true then it loops through the map checking to see if the records billing state is equal to the current Territory States name, if it is, it sets the records Territory state to
Territory States id and then if the Territory state has a regional rep, set the the Accounts Owner to that rep! 
*/
  //THERE IS NOTHING FROM THE OLD CODE LEFT!!!
  //map to hold all of the info from the territory state Object
  map<id, Territory_State__c> TSmap = new map<id, Territory_State__c>([select id, name, Regional__c from Territory_State__c]);
  
  //loop through the trigger
  for (Account A: Trigger.new){
    
    //check to see if the billingstate has a value and the that the billing state and territory state name are not the same
    if(A.BillingState!=null && A.Territory_State__r.Name != A.BillingState){      
      
      //loop through the the territory state map
      for (id TS: TSmap.keySet()) 
        {
          //test if the triggers billingstate is equal to the current territory state in the loop (from the map)
          if(A.BillingState == TSmap.get(TS).name){
            //if it is then set the the trigger record's territory state to equal the id of the current map iteration
            A.Territory_State__c = TS;
            //if the current map iteration's regional rep is set, assign that rep to the triggers OwnerID
            
            if (TSmap.get(TS).Regional__c != null)  A.OwnerId = TSmap.get(TS).Regional__c;
          }
  
        }
    
    }
    
    if (trigger.isInsert)
        {
          //if any of these are empty, throw an error, this error needs to be caught in any testing with an exception
          if (A.BillingStreet ==  null || A.BillingState == null || A.BillingPostalCode == null || A.BillingCity == null)
            {
              A.adderror('Billing Address must be filled out to save record');  
            }
        }
          
  }
    

  
  
}

 

here is the error from the XML result of the push:

 

Class.Accounts.SetState: line 5, column 31
Trigger.AccountUpdateState: line 9, column 4</Message>
          <StatusCode>CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY</StatusCode>
        </SyncError>
      </Errors>
      <UserID>0</UserID>
      <DealerID>945</DealerID>
      <MS_SF_UpsertType>1</MS_SF_UpsertType>
      <CreatedDate>9/7/2011</CreatedDate>
    </SyncResults>
    <SyncResults>
      <MS_SF_SyncID>0</MS_SF_SyncID>
      <Created>false</Created>
      <Success>false</Success>
      <Errors>
        <SyncError>
          <Fields />
          <Message>AccountUpdateState: execution of BeforeUpdate

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

 

Thank you!

Starz26Starz26

I would be willing to bet that a workflow or something is causing recursive updates.....

 

When you get the error, how many records are you updating, 1, 5, 100?

 

I

 

 

KidNikiKidNiki

Sorry Starz26, I was unavailable.  The .Net program updates 200 records at a time right now.  Another thing, on Firday I disabled this trigger, so there are no triggers on the Account object.  Yet we still get the same error?  It blows my mind. I'll ask my administrator about the workflow though, thank you!  Any other thoughts would be greatly appreciated!