You need to sign in to do that
Don't have an account?
raman123
how can i write test class for change of case ownwer and email class
trigger Trigger_case_Send_Email on case (after update) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Set<Id> ownerIds = new Set<Id>();
for (case mycase : Trigger.new) {
case oldcon = Trigger.oldMap.get(mycase.Id);
if (mycase.ownerid != oldcon.ownerid ) {
ownerids.add(oldcon.ownerid) ;
}
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :ownerIds]);
for(case cas : Trigger.old)
{
User theUser = userMap.get(cas.ownerId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new string []{theuser.Email};
mail.setToAddresses(toAddresses);
mail.setSubject('A case owned by you has been transfer');
string mailBody = 'Link: '+ URL.getSalesforceBaseUrl().toExternalForm()+ '/'+Cas.Id;
mail.setPlainTextBody(mailBody);
mails.add(mail);
}
Messaging.SendEmail(mails);
}
}
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Set<Id> ownerIds = new Set<Id>();
for (case mycase : Trigger.new) {
case oldcon = Trigger.oldMap.get(mycase.Id);
if (mycase.ownerid != oldcon.ownerid ) {
ownerids.add(oldcon.ownerid) ;
}
Map<Id, User> userMap = new Map<Id,User>([select Name, Email from User where Id in :ownerIds]);
for(case cas : Trigger.old)
{
User theUser = userMap.get(cas.ownerId);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new string []{theuser.Email};
mail.setToAddresses(toAddresses);
mail.setSubject('A case owned by you has been transfer');
string mailBody = 'Link: '+ URL.getSalesforceBaseUrl().toExternalForm()+ '/'+Cas.Id;
mail.setPlainTextBody(mailBody);
mails.add(mail);
}
Messaging.SendEmail(mails);
}
}
Raj Vakati
100 % ... use this code