You need to sign in to do that
Don't have an account?
URGENT: caused by: System.LimitException: Too many SOQL queries: 101
System was working fine until this morning, now all of a sudden is starting to generate this email error notification. Can anyone help steer me in the right direction?
ERROR MESSGE: The following errors were encountered while processing an incoming email:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : emailAttachmentReassigner: execution of BeforeInsert
caused by: System.LimitException: Too many SOQL queries: 101
Trigger.emailAttachmentReassigner: line 13, column 1 CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : emailAttachmentReassigner: execution of BeforeInsert
caused by: System.LimitException: Too many SOQL queries: 101
Trigger.emailAttachmentReassigner: line 13, column 1 CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : emailAttachmentReassigner: execution of BeforeInsert
caused by: System.LimitException: Too many SOQL queries: 101
Please review the code related to this trigger:
emailAttachmentReassigner
Ensure it's not doing any SOQL statements in loops. If you need help with this, please post the code.
Hi Sean... Thanks for your response. The trigger is below. I greatly appreciate your help as I am new to triggers and did not write this original one. Had been working for years to my knowledge an now real change to it.
1// Jonathan Hersh - jhersh@salesforce.com
2// November 13, 2008
3
4trigger emailAttachmentReassigner on Attachment (before insert) {
5 for( Attachment a : trigger.new ) {
6 // Check the parent ID - if it's 02s, this is for an email message
7 if( a.parentid == null )
8 continue;
9
10 String s = string.valueof( a.parentid );
11
12 if( s.substring( 0, 3 ) == '02s' )
13 a.parentid = [select parentID from EmailMessage where id = :a.parentid].parentID;
14
15 }
16}
Well you have to bulkify your trigger.
Your trigger seems to have a SOQL inside a for loop which is not considered as a good practice.
I made some changes to your code to bulkify the same.
PS : May contain syntax errors
Ok so based off the logic I see in this trigger, what you're doing is checking if the Attachment's parent is an EmailMessage. If so you're re-parenting it to the Parent of the Email Message.
The problem line would be line 13, where the it's looping through each attachment and querying the email message object. If I'm assuming the business case correctly try the below code... it should do what you need but be bulk safe:
Thank you!!! So you think the reason this error is throwing is due to an attachment in the email they are attempting to send to case?
Also, do I first need to write the trigger and test class within the sandbox then deploy as a new trigger and delete the original problem trigger? Sorry for the naivety, but would you be able to help with the test class?
If the trigger is already in production, then I assume there is already a test class that covers the trigger. If so you don't really need to change anything with the test class.
You'll want to simply overwrite the code in the Sandbox org and deploy it to production. (You can run your test class in sandbox to make sure the test class still works).
Yes the test class still passes. There seems to be an error the new trigger though.
Error: Compile Error: Invalid type: Attachmment at line 22 column 11
Spelling mistake ... Sorry about that... try this:
Excellent. It's not throwing the error anymore. Question, would I be updating the class or the trigger and which do I deploy to production? Both a class and a trigger exist with the same code.
Thanks!!!!
I'm not sure why both a class and a trigger exist with the same code. So I can't say for sure on that. However, in terms of getting it resolved in Prod ASAP, I would update the trigger in sandbox and just deploy the trigger.