You need to sign in to do that
Don't have an account?
R R M
Trigger works in sandbox but not in production, please do help
I wrote a trigger that works perfectly in sandbox and has 83% test coverage and deployed it to production, then Trigger was worked smoothly up to 9 months,from 5days back onwords its not working in the production instance where as Working in Sandbox now also and I don't get any error messages, but the thing that it's supposed to do (Query and fill customer field in Case Based on SuppliedEmail) just doesn't happen. In production, it also has 83% coverage. Any ideas what's going on?
Here's the code:
Trigger CaseCustomer on Case (before insert,after update) {
Try{
Set<String> stemail = new Set<String>();
List<Customer__c> custlst = new List<Customer__c>();
Map<String,Customer__c> mpemailtocustomer = new Map<String,Customer__c>();
List<Case> updcaselst = new List<Case>();
Map<String,Entitlement> mpentitle = new Map<String,Entitlement>();
Set<Id> casid = new Set<Id>();
List<CaseMilestone> cmsToUpdate = new List<CaseMilestone>();
if(Trigger.isAfter)
{
for(Case icas:Trigger.New)
{
if((trigger.newMap.get(icas.id).Status!= trigger.oldMap.get(icas.id).Status) && icas.Status == 'Closed')
{
casid.add(icas.id);
System.debug(casid);
}
}
if(casid.size()>0)
{
cmsToUpdate = [select Id,completionDate from CaseMilestone where caseId IN :casid];
System.debug(cmsToUpdate);
}
if(cmsToUpdate.size()>0)
{
for(CaseMilestone icasn:cmsToUpdate)
{
icasn.completionDate = System.now();
}
update cmsToUpdate;
}
}
else
{
for(Case icas:Trigger.New)
{
if(icas.SuppliedEmail != null)
{
stemail.add(icas.SuppliedEmail);
System.debug(stemail);
}
}
if(stemail.size()>0)
{
custlst = [SELECT ID,Email__c FROM Customer__c WHERE Email__c IN:stemail];
System.debug(custlst);
}
if(custlst.size()>0)
{
for(Customer__c icus:custlst)
{
mpemailtocustomer.put(icus.Email__c,icus);
System.debug(mpemailtocustomer);
}
}
List<Entitlement> entlst = [SELECT id,Name FROM Entitlement];
if(entlst.size()>0)
{
for(Entitlement ient :entlst)
{
mpentitle.put(ient.Name,ient);
}
}
for(Case icas : Trigger.New)
{
if(mpemailtocustomer.containskey(icas.SuppliedEmail))
{
icas.Customer__c = mpemailtocustomer.get(icas.SuppliedEmail).ID;
}
if(icas.Origin == 'Email' || icas.Origin == 'Phone' || icas.Origin == 'Web')
{
icas.EntitlementId = mpentitle.get('Response').Id;
System.debug(icas.EntitlementId);
}
}
}
}catch(exception e)
{
System.debug(e.getlinenumber()+e.getmessage());
}
}
Trigger CaseCustomer on Case (before insert,after update) {
Try{
Set<String> stemail = new Set<String>();
List<Customer__c> custlst = new List<Customer__c>();
Map<String,Customer__c> mpemailtocustomer = new Map<String,Customer__c>();
List<Case> updcaselst = new List<Case>();
Map<String,Entitlement> mpentitle = new Map<String,Entitlement>();
Set<Id> casid = new Set<Id>();
List<CaseMilestone> cmsToUpdate = new List<CaseMilestone>();
if(Trigger.isAfter)
{
for(Case icas:Trigger.New)
{
if((trigger.newMap.get(icas.id).Status!= trigger.oldMap.get(icas.id).Status) && icas.Status == 'Closed')
{
casid.add(icas.id);
System.debug(casid);
}
}
if(casid.size()>0)
{
cmsToUpdate = [select Id,completionDate from CaseMilestone where caseId IN :casid];
System.debug(cmsToUpdate);
}
if(cmsToUpdate.size()>0)
{
for(CaseMilestone icasn:cmsToUpdate)
{
icasn.completionDate = System.now();
}
update cmsToUpdate;
}
}
else
{
for(Case icas:Trigger.New)
{
if(icas.SuppliedEmail != null)
{
stemail.add(icas.SuppliedEmail);
System.debug(stemail);
}
}
if(stemail.size()>0)
{
custlst = [SELECT ID,Email__c FROM Customer__c WHERE Email__c IN:stemail];
System.debug(custlst);
}
if(custlst.size()>0)
{
for(Customer__c icus:custlst)
{
mpemailtocustomer.put(icus.Email__c,icus);
System.debug(mpemailtocustomer);
}
}
List<Entitlement> entlst = [SELECT id,Name FROM Entitlement];
if(entlst.size()>0)
{
for(Entitlement ient :entlst)
{
mpentitle.put(ient.Name,ient);
}
}
for(Case icas : Trigger.New)
{
if(mpemailtocustomer.containskey(icas.SuppliedEmail))
{
icas.Customer__c = mpemailtocustomer.get(icas.SuppliedEmail).ID;
}
if(icas.Origin == 'Email' || icas.Origin == 'Phone' || icas.Origin == 'Web')
{
icas.EntitlementId = mpentitle.get('Response').Id;
System.debug(icas.EntitlementId);
}
}
}
}catch(exception e)
{
System.debug(e.getlinenumber()+e.getmessage());
}
}
Hi,
Below Error Am Getting
What i can do, Please help.