You need to sign in to do that
Don't have an account?
Too many Soql 101 Exception in the below attached code
trigger EmailNotificationForQuote on Case (after insert, after update) {
set<id> se1=new set<id>();
List<Case> c1=new List<Case>();
for (Case c : Trigger.new)
{
se1.add(c.Id);
}
if(se1.size() > 0)
{
c1=[Select id,Case_Record_Type__c,Quote_Number__c,testtext__c,testDifferenceDate__c from Case where id IN:se1];
for(Case newCase:c1 ){
System.debug(Trigger.new.size()+'------chiru--');
System.debug(newCase+'------chiranth--');
if(newCase.Case_Record_Type__c =='Quotes' && newCase.Quote_Number__c !=null&& newCase.testtext__c=='Incoming'&& newCase.testDifferenceDate__c==2){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'tets@gmail.com'};
mail.setToAddresses(toAddresses);
string subject='Hi';
string body='Hw ttttttttttttttttttttttttttttt u';
mail.setSubject(subject);
mail.setPlainTextBody('Hhhhhhhhhhhhhhhhh');
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
newCase.Sub_Status__c='Follow-Up';
}
}
update c1;
}
}
Please help me on this.
Thanks
Hi,
You call a DML update on the case record which will fire the trigger again, causing an infinite loop.
Regards,
Hengky
You can get the idea from here
http://www.salesforce.com/docs/developer/cookbook/Content/apex_controlling_recursive_triggers.htm
Regards,
Hengky
trigger EmailNotificationForQuote on Case (after insert, after update) {
string se1;
List<Case> c1=new List<Case>();
for (Case c : Trigger.new)
{
se1=c.Id;
}
if(se1.size() > 0)
{
c1=[Select id,Case_Record_Type__c,Quote_Number__c,testtext__c,testDifferenceDate__c from Case where id =:se1];
for(Case newCase:c1 ){
System.debug(Trigger.new.size()+'------chiru--');
System.debug(newCase+'------chiranth--');
if(newCase.Case_Record_Type__c =='Quotes' && newCase.Quote_Number__c !=null&& newCase.testtext__c=='Incoming'&& newCase.testDifferenceDate__c==2){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'tets@gmail.com'};
mail.setToAddresses(toAddresses);
string subject='Hi';
string body='Hw ttttttttttttttttttttttttttttt u';
mail.setSubject(subject);
mail.setPlainTextBody('Hhhhhhhhhhhhhhhhh');
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
newCase.Sub_Status__c='Follow-Up';
}
}
update c1;
}
}
Try the above code
Regards,
Magulan D
Salesforce.com certified Force.com Developer.
SFDC Blog
If this post is your solution, kindly mark this as the solution.
I was very useful thanks
Where to start?
1. This should be a before query, not an after query.
2. You are doing a query inside the for loop. This is not best practices and is probably why you are getting the too-many-queries error.
3. You don't need to execute a query at all - all of the data you need is already available within the system.trigger.new list.
4. If this were a before query, you wouldn't need to do an update at all.
5. You are doing DML inside the for loop. This is not best practices.
6. You are sending an email inside the for loop. This is not best practices.
I am not going to do your work for you but you should be able to reduce the number of lines of code by half.
Hi after chaning the code i came up with a trigger which works fine for me
trigger EmailNotificationForQuote on Case (after insert, after update){
set<id> idSet=new set<id>();
List<Case> caseList=new List<Case>();
if(SomeClass.someValue){
SomeClass.someValue = false;
for(Case c : Trigger.new){
idSet.add(c.Id);
}
if( idSet!=null && idSet.size() > 0){
try{
caseList=[Select id,Case_Record_Type__c,Quote_Number__c,testtext__c,testDifferenceDate__c from Case where id IN:idSet];
}catch(QueryException qe){}
if( caseList !=null && caseList.size() >0 ){
for(Case newCase:caseList ){
if(newCase.Case_Record_Type__c =='Quotes' && newCase.Quote_Number__c !=null&& newCase.testtext__c=='Incoming'&& newCase.testDifferenceDate__c==3){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'test@test.com'};
mail.setToAddresses(toAddresses);
string subject='Hi';
string body='Hw r u';
mail.setSubject(subject);
mail.setPlainTextBody('Hhhhhhhhhhhhhhhhh');
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
newCase.Sub_Status__c='Follow-Up';
}
}
}
update caseList;
}
}
}
Thanks for all your help