I have below Peice of code which is chekcing if its sandbox then run If part else run Else part

    if(runningInASandbox()) {
                    return getSsoRedirect('one', startUrl, requestAttributes); //call sso flow 
                else {
                    return getSsoRedirect('two',startUrl, requestAttributes); //call sso flow 

Now I am running test class its covering if part ,beacasue i am running from sandbox.how to cover else part as well in test class.Please suggest


Since the result will not change typically from run to run you need a way to be able to set the result if you want. Lazy loading helps. Then in your test you can set it to return a value

@testVisible private static Organization org {
              If(org == null){
                     Org = [select isSandbox from organization limit 1];


               Return org;




Public static Boolean runningInASandbox(){

     Return org.isSandbox;


Then in your tests set

ClassName.org = new Organization(isSandbox = true;

Note I typed this on mobile so will probably be buggy or need slight mods

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.