Salesforce Interview questions with answers Part 25

Salesforce Interview questions with answers Part 25

1. Below is the code snippet , How to get the code coverage for the constructor?

public class test {
boolean flag;
public test(){
if(flag == true) {
String s= ‘blue’;
}
if(flag == false) {
String s= ‘red’;
}
}
}

Answer:

public class test {
    @testVisible static boolean flag;
 
    public test() {
        if(flag == true) {
            String s= ‘blue’;
        }
        if(flag == false) {
            String s= ‘red’;
        }
    }
}


@isTest
public class testClass {
    static testMethod void testMtd() {
        test.flag = true;
        test t = new test();
        test.flag = false;
        t = new test();
    }
}

2. How to access the variables of the inner wrapper class(InnerWrapper) in VF Page for the below code

public class Main {


public class Outerwrapper {


public String outerwrap{get;set;}
public Outerwrapper(String m){
}
public class InnerWrapper {
public String innerwrap{get;set;}
public InnerWrapper(String s){
}
}


}


}

Ans:
Salesforce doesn’t support more than 1 level of inner classes.

3.How do you monitor future calls in Salesforce Standard UI ?

Setup –> Jobs –> Apex Jobs


4.How to pass list of checkboxes checked using javscript to controller class ?


Set the id to the checkbox and get the value using JS.


5.How do you distinguish between xml and json in Rest API Call while invoking web service?


JSON is the default. You can use the HTTP ACCEPT header to select either JSON or XML, or append .json or .xml to the URI (for example, /Account/001D000000INjVe.json)

Cheers!!!

Leave a Reply