You need to sign in to do that
Don't have an account?
how to write Test Case for a ApexClass
Hi All,
Give me some idea on cases that i create a customfield reply__c in case and i create a ApexClass Agentreply and my problem is Write a test Case with 75 % please help me it is very urgent............
public class AgentReply
{
public Case objCase
{ get; set; }
public CaseReply__c objCaseReply
{ get; set; }
public User objUser
{ get; set; }
public String EmailBody
{ get; set; }
public AgentReply()
{
objCase = [Select Subject,Requestor_Email__c, OwnerId, Id, Description,Priority,
...... CaseReply__c From Case where id = :ApexPages.currentPage().getParameters().get('id')];
EmailBody = 'Add your reply here!!!';
}
// this method is call from the Visualforce page to save the Reply in the CaseReply__c Custom object
public void save()
{
//As per email review logic, check manual approval or auto
Case oCase = [Select Id,Subject,ReplyStatus__c From Case where
id=:ApexPages.currentPage().getParameters().get('id')];
CaseReply__c oCaseReply = new CaseReply__c();
oCaseReply.AgentReply__c = emailBody ;
oCaseReply.Name = oCase.Subject;
oCaseReply.rCase__c = oCase.Id;
insert oCaseReply;
Boolean checkFlag = ReviewAgentEmail();
if(checkFlag == true)
{
oCase.ReplyStatus__c = 0;
update oCase;
}
else
{
oCase.ReplyStatus__c = 2;
update oCase;
//send direct email and mark case as replied
sendEmail();
}
updateEmailCount();
}
// Method of updateEmailCount
public void updateEmailCount()
{
User oUser = [Select EmailCount__c from User WHERE id=:UserInfo.getUserId()];
if(oUser.EmailCount__c == 10){
oUser.EmailCount__c = 1;
}else{
oUser.EmailCount__c = oUser.EmailCount__c + 1;
}
update oUser;
}
// Method of send Email process
public void sendEmail()
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] to_Address = new String[]{};
String[] cc_Address = new String[]{};
String[] bcc_Address = new String[]{};
if(objCase.Contact.Email != null)
to_Address.add(objCase.Contact.Email);
if(objCase.Requestor_Email__c != null)
to_Address.add(objCase.Requestor_Email__c);
to_Address.add('ganeshd@cybage.com');
mail.setToAddresses(to_Address);
if(objCase.Contact_Email_Alias__c != null)
cc_Address.add(objCase.Contact_Email_Alias__c);
mail.setCcAddresses(cc_Address);
User objUser = [Select Email from User where Id =:UserInfo.getUserId()];
if(objUser.Email != null)
mail.setReplyTo(objUser.Email);
mail.setSaveAsActivity(true);
mail.setSubject(objCase.Subject);
mail.setHTMLBody(emailBody);
mail.setPlainTextBody(emailBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
// Method for ReviewAgentEmail
public boolean ReviewAgentEmail()
{
User oUser =[Select EmailCount__c from User where Id =:UserInfo.getUserId()];
Double currentEmailcount;
if(oUser.EmailCount__c == null)
{
currentEmailcount = 0;
}
else
{
currentEmailcount = oUser.EmailCount__c;
}
if(currentEmailCount == 10)
{
currentEmailcount = 1;
}
else
{
currentEmailcount = currentEmailcount + 1;
}
EmailReview__c emailRev = [Select DoReview__c, EmailNum__c from EmailReview__c where EmailNum__c =:currentEmailCount and Name =:UserInfo.getUserId()];
if(emailRev.DoReview__c == 1)
{
return true;
}
else
{
return false;
}
}
}
give me some idea on this issue
thanks u guys.......
Try the following article:
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods