You need to sign in to do that
Don't have an account?

Simple Testclass
Update:
I tried a bit an made the method with queries alle case-emails returning the value itself:
public List<EmailMessage> ViewData(string incId) {
String query = 'Select ToAddress, TextBody, SystemModstamp, Subject, Status, ParentId, '
+ 'MessageDate, LastModifiedDate, LastModifiedById, IsDeleted, Incoming, '
+ 'Id, HtmlBody, Headers, HasAttachment, FromName, FromAddress, CreatedDate, '
+ 'CreatedById, CcAddress, BccAddress, ActivityId '
+ 'From EmailMessage WHERE '
+ 'ParentId = \''+ incId + '\'';
//+ 'ParentId = \''+ incident.Id + '\'';
myquery = query;
myEmail = Database.query(query);
return myEmail;
}
but now my apex page can't access the controller extension:
<apex: page standardController="Case" extensions="mySendMail" action="{!ViewData}" id="mySendMail_PageLoad">
results in >>> Unknown method 'CaseStandardController.ViewData() <<<<
why is that? i did this because i wanted to access the method from my testclass with a case id
and compare the anticipated results.
please note that incident and case are the for the same thing
__________________________________________________________________________________________
Hi there, i'm a bloody beginner in apex and i don't know how to write a simple test-class
for the following controller extension of the case controller :
it was written to avoid an "email to:" field from beeing filled with the
standard contact for the account associated with the case when replying to a mail
in the case. it is called in a special section within the case-vf page. all emails
for this case are displayed an can be replyed by link. it works perfectly but must be
tested as you know.
public class mySendMail {
private List<EmailMessage> myEmail;
public List<EmailMessage> getmyEmail() {return myEmail;}
public string myquery {get;set;} // testqueryoutput in page
public string caseId {get;set;} // caseId-exchange
//standardcontrollerfunctionality
Case incident;
ApexPages.StandardController controller;
public mySendMail(ApexPages.StandardController controller) {
this.controller = controller;
this.incident = (Case)controller.getRecord();
}
public PageReference ViewData() {
String query = 'Select ToAddress, TextBody, SystemModstamp, Subject, Status, ParentId, '
+ 'MessageDate, LastModifiedDate, LastModifiedById, IsDeleted, Incoming, '
+ 'Id, HtmlBody, Headers, HasAttachment, FromName, FromAddress, CreatedDate, '
+ 'CreatedById, CcAddress, BccAddress, ActivityId '
+ 'From EmailMessage WHERE '
+ 'ParentId = \''+ incident.Id + '\'';
myquery = query;
myEmail = Database.query(query);
return null;
}
}
the code below is my testclass attempt so far. i have no idea how to call
a testcase of mine from which i know what emails and their subjects are.
i simply wanna compare the amount of emails or some or one subject.
@IsTest private class mySendMailTest {
//initializing the standard case controller
ApexPages.StandardController con = new ApexPages.StandardController(new Case());
//initializing the controllerextension
mySendMail ext = new mySendMail(con);
public static testmethod void basicTest() {
}
}
PageAction methods must return PageReference or void. You can't return a list of anything to a page from a PageAction method. If what you are trying to do is test the ActionMethod, use:
Test.setCurrentPageReference(ApexPages.PageReference)
Set this to your initial context (your wrapper page) and set the return of a local PageReference variable to the results of your action method
PageReference testPage = ext.ViewData();
All Answers
PageAction methods must return PageReference or void. You can't return a list of anything to a page from a PageAction method. If what you are trying to do is test the ActionMethod, use:
Test.setCurrentPageReference(ApexPages.PageReference)
Set this to your initial context (your wrapper page) and set the return of a local PageReference variable to the results of your action method
PageReference testPage = ext.ViewData();
Thanks! This is my testclass now and it covers 86% of code.
that's fine but i'm open for suggestions how to cover more code.
@IsTest private class mySendMailTest {
public static testmethod void basicTest() {
Case incident;
incident = [SELECT Id FROM Case LIMIT 1];
ApexPages.StandardController con = new ApexPages.StandardController(incident);
System.debug(incident.id);
mySendMail ext = new mySendMail(con);
PageReference mySendMail = ext.ViewData();
List<EmailMessage> myEmail;
}
}