function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karthikeya 2karthikeya 2 

test class for update the case object record?

hi all,

I wrote a test class but i am unable to cover the test coverage for that ineed below sample code
I am retriving case object fields in controller based on ID in URL.
And updating the same object with new fields.

can any one give the sample test class for this.

Thanks in Advance.
Richard Jimenez 9Richard Jimenez 9
Hi Karthikeya,

To get code coverage for your class you need to create a test(s) that will execute the lines of code in your controller class. Based on what your code does, you should think about several different tests you should have that will test you code works correctly (and other things like handling errors conditions or bulkfication)  i.e. if you input X in you get Y out.

Check out the 'Test Methods and Visualforce Controllers' section  in this guide :

Hope that helps,
Richard Jimenez
Hi Karthikeya,

Seems you forgot to put your code. 

As per my understanding you are trying to get some fo values from URL parameters and placing them into some of fields in your class. for that you need to first set the url parameter before you call the actual class method.

this code can help you or give some idea

for instance if your url parameter is "ID"
then set that id as below

Make sure on giving parameter name as it is case sensitive.

let me know, if it helps you or need any help :)
Mahesh DMahesh D
Hi karthikeya,

Please paste the actual class and test class then it will be easy to help you.

Mahesh DMahesh D
Hi Karthikeya,

Please look into the below code:
private class CaseExtensionControllerTest {

    static testMethod void testCaseExt() {
		// Create the Case Record.
        Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email'); 
        insert cas;
		// Set the parameter id with the created case id.
        ApexPages.currentPage().getparameters().put('id', cas.Id);
		// Instantiate the Controller Class.
        CaseExtensionController cec = new CaseExtensionController();
		// Call the corresponding methods. 
		// If needed set some of the variable values before calling certain methods.
        cec.selectedOption = 'All';

As I am not able to see your code, this is the sample code which you have to change according to your class and variables.

Still if you are facing any problem then , post your Class here so that it will be easy to provide you the answer.

Please do let me know if it helps you.