You need to sign in to do that
Don't have an account?
llisa
Hello Everyone i am stuck on the test class for Emailbody...please someone help me on this.
public class KEmailBodyController{
public K_Approval_Request_Body__c body{get;set;}
String kId = '';
public KEmailBodyController(){
body = new K_Approval_Request_Body__c();
kId = ApexPages.currentPage().getParameters().get('id');
if(common.NVL(kId) != ''){
List<K_Approval_Request_Body__c> lstBody = [Select Id, Body__c, Related_Document__c, Status__c
From K_Approval_Request_Body__c Where Related_Document__c=:kId and Status__c = 'Pending' Limit 1];
if(lstBody != null && lstBody.size()>0){
body = lstBody[0];
}
else{
body.Related_Document__c = kId;
body.Status__c = 'Pending';
}
}
}
public void save(){
if(body != null && common.NVL(body.Body__c) != ''){
upsert body;
}
}
}
Plese help me,i have totally no idea about test classes.
public K_Approval_Request_Body__c body{get;set;}
String kId = '';
public KEmailBodyController(){
body = new K_Approval_Request_Body__c();
kId = ApexPages.currentPage().getParameters().get('id');
if(common.NVL(kId) != ''){
List<K_Approval_Request_Body__c> lstBody = [Select Id, Body__c, Related_Document__c, Status__c
From K_Approval_Request_Body__c Where Related_Document__c=:kId and Status__c = 'Pending' Limit 1];
if(lstBody != null && lstBody.size()>0){
body = lstBody[0];
}
else{
body.Related_Document__c = kId;
body.Status__c = 'Pending';
}
}
}
public void save(){
if(body != null && common.NVL(body.Body__c) != ''){
upsert body;
}
}
}
Plese help me,i have totally no idea about test classes.
Please try below Test Class
All Answers
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
http://amitsalesforce.blogspot.in/2015/06/salesforce-testing-best-practice.html
http://amitsalesforce.blogspot.in/2015/05/testsetup-set-up-test-data-for-entire.html
http://amitsalesforce.blogspot.in/2015/02/starttest-and-stoptest-method.html
Please let us know if this will help you
Thanks
Amit Chaudhary
thanks for your help,but it is not working for "KEmailBodyController".
it is showing 0% code coverage.ang the "boolean displayPopup = true" ang pagrreference thing is not there in "KEmailBodyController".CLASS also.
my class is --
public class KEmailBodyController{
public K_Approval_Request_Body__c body{get;set;}
String kId = '';
public KEmailBodyController(){
body = new K_Approval_Request_Body__c();
kId = ApexPages.currentPage().getParameters().get('id');
if(common.NVL(kId) != ''){
List<K_Approval_Request_Body__c> lstBody = [Select Id, Body__c, Related_Document__c, Status__c
From K_Approval_Request_Body__c Where Related_Document__c=:kId and Status__c = 'Pending' Limit 1];
if(lstBody != null && lstBody.size()>0){
body = lstBody[0];
}
else{
body.Related_Document__c = kId;
body.Status__c = 'Pending';
}
}
}
public void save(){
if(body != null && common.NVL(body.Body__c) != ''){
upsert body;
}
}
}
and test class is---
@isTest
private class test_KEmailBodyControllerTest
{
static testMethod void test_KAddNoteControllers1()
{
K_Approval_Request_Body__c kApproval = new K_Approval_Request_Body__c();
kApproval.Body__c ='TEST1';
kApproval.Related_Document__c ='TEST2';
kApproval.Status__c ='TEST3';
insert kApproval;
PageReference pageRef = Page.KEmailBody; // Add your VF page Name here
pageRef.getParameters().put('id', String.valueOf(kApproval.id));
Test.setCurrentPage(pageRef);
KEmailBodyController controller = new KEmailBodyController();
controller.save();
}
}
Hey AMIT can we communicate throught mail?
I did canges on my apex class but it dont work,0% code coverage is showing.
Please try the below test class :
Regards,
Abhishek.
You will not see any changes in Code Coverage unless you run it agian.
So make sure that you are running your test class each time after you are doing changes in it.
Each time when i update ,i run the test class.
Here "Related_Document__c" having master detail relationship with another object.
so in this code it gives an error "Invalid Type-Related_Document__c"
Please try below Test Class