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

Need Help with Apex Test Class
I wrote a basic APEX Class that helps create a case from a VisualForce page and need to write a test class for it. I am far from being a developer and managed to get the class uop and running but I do not have the foggiest idea where to start for a test class
public class SubmitCaseController { public Case c { get; set; } public SubmitCaseController() { c = new Case(); } public PageReference submitCase() { try { // Specify DML options to ensure the assignment rules are executed Database.DMLOptions dmlOpts = new Database.DMLOptions(); c.Created_By_User__c = UserInfo.getUserId(); c.OwnerId = '00G30000003El5v'; c.RecordTypeId = '012n00000004I1r'; c.Origin = 'Internal Ticketing'; c.setOptions(dmlOpts); // Insert the case INSERT c; return new PageReference('/apex/thank_you_case_submission'); } catch (Exception e) { ApexPages.addMessages(e); return null; } } }
Hey ,
Go for this post it will definetly help in your code and as well clear your doubts
http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html
All Answers
Checkout this link and let me know if you still have any questions. Writing a tst class is not a diffcult thing as you already know how to write an apex class.
Apex Test Class
@IsTest(SeeAllData=true)
static testmethod void testNegativeChangecaseOwnerController()
{
test.startTest();
SubmitCaseController obj = new SubmitCaseController();
obj.submitCase();
test.stopTest();
}
If it helps you please mark as solved :)
IsTest(SeeAllData=true)
static testmethod void testNegativeChangecaseOwnerController()
{
test.startTest();
Case testCase = new Case();
testCase.Status = 'New';
testCase.OwnerId = '00G30000003El5v';
testCase.RecordTypeId = '012n00000004I1r';
testCase.Origin = 'Internal Ticketing';
insert testCase;
SubmitCaseController obj = new SubmitCaseController();
obj.submitCase();
test.stopTest();
}
Hey ,
Go for this post it will definetly help in your code and as well clear your doubts
http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html
Thank you eveyone for the suggestions, I have marked Abhi's as the bet as it did a great job of explaining how to create future test classes.