You need to sign in to do that
Don't have an account?
t.deepthi05
Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace:
I am deploying my code to production and i am getting the below error
My trigger
trigger OpportunityTrigger on Opportunity (after delete, after insert, after undelete,
after update, before delete, before insert, before update) {
if(Trigger.isAfter && Trigger.isInsert){
{
EncryptURl.insertOpp(Trigger.new,Trigger.newMap.keySet());
}
}
and my trigger class is
public static void insertOpp(Opportunity[] o,Set<id> newMapKeySet)
{
list<Opportunity> oppsToUpdate =[select id,Encrypted_URL__c from Opportunity where id IN :newMapKeySet];
for(Opportunity op:oppsToUpdate){
if(op.id != null){
string oppid=op.id;
Blob dataLead = Blob.valueOf(oppid);
String b64Data = EncodingUtil.base64Encode(dataLead);
string oppURL =Label.PWV_FavoriteURL+'oId='+b64Data;
op.Encrypted_URL__c =oppURL;
}
}
try{
update oppsToUpdate;
}catch(exception e){
system.debug('DMl exception'+e);
}
}
can i know how to over the soql exception
My trigger
trigger OpportunityTrigger on Opportunity (after delete, after insert, after undelete,
after update, before delete, before insert, before update) {
if(Trigger.isAfter && Trigger.isInsert){
{
EncryptURl.insertOpp(Trigger.new,Trigger.newMap.keySet());
}
}
and my trigger class is
public static void insertOpp(Opportunity[] o,Set<id> newMapKeySet)
{
list<Opportunity> oppsToUpdate =[select id,Encrypted_URL__c from Opportunity where id IN :newMapKeySet];
for(Opportunity op:oppsToUpdate){
if(op.id != null){
string oppid=op.id;
Blob dataLead = Blob.valueOf(oppid);
String b64Data = EncodingUtil.base64Encode(dataLead);
string oppURL =Label.PWV_FavoriteURL+'oId='+b64Data;
op.Encrypted_URL__c =oppURL;
}
}
try{
update oppsToUpdate;
}catch(exception e){
system.debug('DMl exception'+e);
}
}
can i know how to over the soql exception
"Too many SOQL queries: 101".
This error System.LimitException: Too many SOQL queries: 101is due to the fact, you are hitting on governor limit. The governor limit that says we can run total 100 SOQL queries in a context and you are hitting the limit.
All the triggers fired will be counted in a single context or call. We need to ensure that total number of SOQL fired should be less than 100.
In order to by pass this, you need to change your code in such a way that SOQL fired must be less than 100 or if you need to change the context then you can use @future annotation which will run the code asynchronously.
You need to make sure that the SOQL query you are using should not be inside the for loop.
There are certain best practices which you would have to follow to avoid this error (to avoid hitting governor limit).
1. http://wiki.developerforce.com/page/Best_Practice:_Avoid_SOQL_Queries_Inside_FOR_Loops
2. http://salesforcedeveloperblog.blogspot.com/2011/05/best-practices-of-triggers.html
3. http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bestpract.htm
4. http://wiki.developerforce.com/page/Apex_Code_Best_Practices
If you follow the above practices, the error will stop. Moreover there is no way wherein we in Salesforce can increase the
governor limit or can stop it so best practices need to be followed.
https://developer.salesforce.com/page/Best_Practice:_Avoid_SOQL_Queries_Inside_FOR_Loops
Try removing after insert, after update and after delete events so that u dont require to soql query to get opp records.
Let me know its woring or not.
k Then Try using after events, can u tel me what ur trying to do with this.
pavanthetech@gmail.com
I implemented the recurssive logic but still facing the same error
Is your test class passed in the sandbox, if it is passed, check the deployment errors, there might be some other apex component is giving error.
Once you run All tests in production ( develop > apex test execution) , then disable parallel apex test runs (settings)
Then make your user as debug user and try to validate the changeset again and check the debug log for complete process ( make sure you disabled parallel apex test execution)
Since you want to update a field using Id, you can remove after delete, after update and before insert trigger events
You can stop recurcive triggers since you are using before update trigger event
I added the logic of isRecursive = true; and i was able to deploy fine