You need to sign in to do that
Don't have an account?
Med Usa1
Deploying a trigger : System.LimitException
Hello,
I try to deploy a trigger and its test class in production but I have this error :
Failure Message: "System.LimitException: Too many query rows: 50001", Failure Stack Trace:...
The code coverage of this trigger is 100%.
I think the pb is due to another test class for another trigger but the both (the 2 triggers and the 2 test classes) are on the same object (Opportunity).
The other trigger is already deployed.
How can I solve this problem ?
Thank you.
Could you please post your trigger code?
It looks as if you are trying to query more than 50,000 records in your trigger, which exceeds the Governor Limits.
I have solved this error by adding a WHERE close in my query.
But I have another error now :
System.LimitException: Too many SOQL queries: 101
Can you help me ?
Yes, I think a WHERE clause is good where ever you know before your query that you really want just a reduced set of records.
Your next exception is caused by the sum of querys you are doing.
This counts as a query:
You should try to avoid making queries inside loops (classic: for-loops!). The "Apex Code Best Practices" will help you to figure out what to do and what better not to do.
One hint: If you post your code, it is more helpful for the others to help you. Now we can just do a general guess about your problems.
My query isn't inside a for loop.
I think the pb comes from another trigger.
My trigger code :
and in the log :
16:04:34.488 (4488734000)|CODE_UNIT_STARTED|[EXTERNAL]|01qD0000000HoNH|ProjectNumberBUonOpportunity on Opportunity trigger event BeforeInsert for [new]
16:04:34.490 (4490137000)|SOQL_EXECUTE_BEGIN|[357]|Aggregations:0|select Id, Business_Unit__c, BU7__c from Opportunity where Business_Unit__c = 'intra-group' order by BU7__c desc
16:04:34.490 (4490186000)|EXCEPTION_THROWN|[357]|System.LimitException: Too many SOQL queries: 101
16:04:34.490 (4490539000)|FATAL_ERROR|System.LimitException: Too many SOQL queries: 101
The other trigger named "ProjectNumberBUonOpportunity" is already deployed for a long time.
I don't understand the pb because the query "select id..." isn't inside a for loop.
Have you an idea ?
Thank you.
Do you have a rough number how many records you are INSERTing at once, so this trigger gets executed?
the error is coming from the other trigger. whatever you are inserting is causing that trigger to hit limits...
Does the other trigger have soql inside loops?
The other trigger has just one for loops and there isn't SOQL inside the loops.
The query where I have the error in the log report "select id...", this query is in a clause "if".
Do you have another idea ?
Thank you for your help.
A far as I know.All the triggers running on a particular object share governor limits.They will not have different governor limits.Can u pleaee post both the triggers and test clases as well?
Moreover,try to use Limits class function to know governor limits being consumed by you code.
In the sandbox you can use data loader to upload data activating this trigger and then se if you particular trigger gives you problem or not.?.
Thanks,
Trick
FYI, aggregate queries count the number of records queried, not returned, for the limits.
So you have a COUNT() aggregate query, where 40,000 records have value X, and 30,000 records have value Y, that's not 2 rows, that's 70,000. Something to keep in mind.
Also, look at the error.....it's on line 357. So it's definitely occurring outside of the trigger that you posted. The query causing issues is probably somewhere else.
I can't post all my trigger's code but here is the part with the error line 357 :
Craigmh, an aggregate query returns all the rows or just the Max or Count ?
I have one in my trigger that makes a Max and it goes inside the for loopsjust one time.
Thank you for your help.
An aggregate query only returns the aggregate results, but ALL of the rows are counted against the limits.
What you could do on line 357, since you only need to know if ANY records that meet the criteria exist, is add a LIMIT 1 clause. You only need to know if the result has zero records, or more than zero, so use the LIMIT keyword to limit the results.
Hello,
I have added "Limit 1" to the query but there is always the same error.
If i have a look to the log file, there is :
And if I look the text log before, I have messages close to limits:
or
Do you have an idea ?
Thank you.
In the trigger where there is the error, I have many "if" clause with a query inside and it seems that after each time it runs a query, the Number of SOQL queries increases even if it is different queries.
Is it possible to reset this number ?
I have also many validation rules that run. Does it count in the number of queries ?
Thank you.
Hi ,
Let me know if you have any issues.
You can reach me at a.k.gupta@salesforce.com
Feel free to contact me any time for Dev issues with details.
Regards,
Amit Kumar Gupta
Salesforce.com