1.) Use a service class to create the test case. 2.) In your test class, call the function/method from step #1. 3.) Now use SOQL to search for the test case number.
1.) Use a service class to create the test case. 2.) In your test class, call the function/method from step #1. 3.) Now use SOQL to search for the test case number.
It depends on the level of testing that you're trying to achieve. If you create a case with ONLY the required fields populated, the code below should work. If you want to test the account and contact fields, you'll have to use the method that I listed in the previous post.
@isTest
public class testCaseForForum{
public static void createTestCase(){
Case testCase = new Case(
Status ='New',
Origin='Phone',
Subject='This is a test case for testCaseForForum');
insert(testCase);
}
public static void getCaseNumber(){
//Use line below to retrieve the entire case
Case testCase = [SELECT CaseNumber, Status, Origin, Subject FROM Case WHERE Subject='This is a test case for testCaseForForum'];
//Use line below to retrieve the case number only
String testCaseNumber = [SELECT CaseNumber FROM Case WHERE Subject='This is a test case for testCaseForForum'].CaseNumber;
}
}
1.) Use a service class to create the test case.
2.) In your test class, call the function/method from step #1.
3.) Now use SOQL to search for the test case number.
All Answers
1.) Use a service class to create the test case.
2.) In your test class, call the function/method from step #1.
3.) Now use SOQL to search for the test case number.
Please expalin clearly,i didnot undestand,please share code if you so that i can understand