How do i cover code coverage for a return statement.I am not using pagereference.

            errMsg='No contacts Selected';//not covered
            return page.importfile;//not covered
        if(smstoggle==false && Emailtoggle==false){
            errMsg='Select the required toggle'; //not covered
            return page.importfile;//not covered
        if(smstoggle|| Emailtoggle){//covered
            sucmsg=null;        //covered      
        if( smstoggle && Emailtoggle){       
              sucmsg=null;//not covered
  • Please update your question with more details, Where did you get stuck? What have you tried so far? Sep 4, 2018 at 7:16
  • I am a noob here in coding test class,i have tried pagereference examples given in sfdc community.I am stuck in return statement.
    – Maneesh
    Sep 4, 2018 at 7:20
  • @Maneesh,How did you resolved this
    – Shiv
    Feb 17, 2019 at 15:32
  • @Shiv I changed the main class.sry man i don't remember the changes I made .It was a long time ago.
    – Maneesh
    Feb 18, 2019 at 9:49

1 Answer 1


Basically you need to call your function multiple times, each time with slightly different parameters or data so that the code enters each if statement.
As you can see, your code ran once with smstoggle = true, and so covered that code.
You need to run it again with all possible permutations of your code:

  • atleastoneselected == false
  • smstoggle==false && Emailtoggle==false
  • smstoggle && Emailtoggle
  • I tried it ,it's not covering,the issue is my test class is not covering any if conditions.
    – Maneesh
    Sep 4, 2018 at 9:32
  • It would help if you would share your code. Sep 4, 2018 at 11:46
  • If your if conditions aren't being covered, you're not tailoring your test data correctly as @AvailableName says. The only way to obtain code coverage is to execute the code.
    – David Reed
    Sep 4, 2018 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .