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
AshwAshw 

unable to do code coverage for this below coved my test code is covering 63%

Hi I'M new to salesforce.com. I'm unable to do code coverage for this below coved my test code is covering 63% only what i have learnt from my training class is simply by covering methods in the class we will get 75%

class:
--------
public with sharing class AccFieldsIn2DiffVfToSave_cls {

    public PageReference doSave() {
        insert objA;
        return (new pagereference('/apex/AccFieldsIn2DiffVfToSave2?id='+obja.Id).setredirect(true));
    }


    public Account objA { get; set; }
   
    public AccFieldsIn2DiffVfToSave_cls(){
        objA = new Account();
    }
}

test class:
--------------

@isTest
private class AccFieldsIn2DiffVfToSave2_tst{
    static testmethod void mytest(){
   
        AccFieldsIn2DiffVfToSave2 obj = new AccFieldsIn2DiffVfToSave2 ();
                  
            obj.doSave();
    }
}
Best Answer chosen by Ashw
mahi1mahi1
hi, In my developerconsole I got 100% code coverage

try again once........

All Answers

mahi1mahi1
hi
you should use mandatory fileds in testclass

class:
--------

public with sharing class AccToSave {

    public PageReference doSave() {
    insert acc;
        return (new pagereference('/apex/AccountToSave').setRedirect(true));
    }


    public Account acc{ get; set; }
   
    public AccToSave(){
    acc = new Account();
    }
}

test class:
-------------

@isTest
private class TestAccToSave{
static testmethod void myTest(){
  AccToSave ats = new AccToSave();
  
  ats.acc.Name = 'SampleAccount';
  pagereference ref = ats.doSave();
}
}
Ramu_SFDCRamu_SFDC
Please read through the following article for best practices of testing https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm
AshwAshw
HI Mahi1 & Ramu_SFDC

Thanks for Your responses that really appreciable, Mahi1 i tried ur code but the code coverage was still same fixed to 62%
mahi1mahi1
hi, In my developerconsole I got 100% code coverage

try again once........
This was selected as the best answer