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
Abhishek Prasad 8Abhishek Prasad 8 

if clause in apex

I am stuck with this if clause in my Test Clasuse. Can anybody help me. Here is my code example
public MethodName(ApexPages.StandardController Controller){

Newflag = false; //(variable Initialized as false)

if(Newflag )
// Do some stuff
//No else present or needed in this case.

When i am trying to pass this method by calling MethodName in my test class, 
and initializing the Newflag as true in the testclass, it not getting passed, as NewFlag is already initialized as false in the main class,
 and the testclass flag is getting overwritten by false. 

What should it do here

Vijaya AmarnathVijaya Amarnath
Hi Abhisek,

You are intializing the variable in Constructer and immediately you are checking that as true or not?.. In real time scenario it'll not happen. Can you give us the exact requirement of this..

Vijaya Amarnath.
Abhishek Prasad 8Abhishek Prasad 8
Thanks for the reply. I am not setting this variable in constructer. its inside one particular method named MethodName. I am setting a variable with false value. next, when i check an if clause with the same value as true. WHen i am writing a testclass for such a scenario, the if portion is not passing as it the value in the main class is set as false. its not taking the value i am setting in testclass.

Please inform if i am making my self clear
Vijaya AmarnathVijaya Amarnath
Hi Abhisek,

Can you share your code?..