You need to sign in to do that
Don't have an account?
Davinder Kaur 8
Trigger working on Sandbox but not working on production
I wrote a trigger to create a new case when a closed case receives a mail. It works absolutely fine on sandbox but not working on production.
trigger EmailMessageAfterUpdate on EmailMessage (after insert) {
// limit 1001 used, else it was giving error "System.LimitException: Too many query rows: 50001".
List<case> caseList = [Select id, Status from Case where Status = 'Closed' limit 1001];
for (EmailMessage newEmail : Trigger.new)
{ for(case cc : caseList){
if(cc.Status == 'Closed' && cc.id == newEmail.ParentId){
Case newCase = new Case();
newCase.Subject = newEmail.Subject;
newCase.Parent_Case__c=newEmail.ParentId;
newCase.Category__c = newEmail.Parent.Category__c;
newCase.BusinessHours = newEmail.Parent.BusinessHours;
newCase.Status = 'Re-Opened';
newCase.Sub_Status__c = newEmail.Parent.Sub_Status__c;
insert newCase;
}
}
}
}
trigger EmailMessageAfterUpdate on EmailMessage (after insert) {
// limit 1001 used, else it was giving error "System.LimitException: Too many query rows: 50001".
List<case> caseList = [Select id, Status from Case where Status = 'Closed' limit 1001];
for (EmailMessage newEmail : Trigger.new)
{ for(case cc : caseList){
if(cc.Status == 'Closed' && cc.id == newEmail.ParentId){
Case newCase = new Case();
newCase.Subject = newEmail.Subject;
newCase.Parent_Case__c=newEmail.ParentId;
newCase.Category__c = newEmail.Parent.Category__c;
newCase.BusinessHours = newEmail.Parent.BusinessHours;
newCase.Status = 'Re-Opened';
newCase.Sub_Status__c = newEmail.Parent.Sub_Status__c;
insert newCase;
}
}
}
}
you can try below code which is more optimized
All Answers
you can try below code which is more optimized
It does not give any error but it is not creating any new case now... Earlier it was working fine on production but now it have stopped working.
Couple of things you can take in to count..
1. there may be no closed cases at all in production or
2. There may be no closed case realted to the incoming email.
And yes code given by @BalajiRanganathan is much optimized than what I written.....
I think I am too much thinking while writing the code for you...