I have this DynamicPickList class that creates picklist values based on what lookups have been put on the Contact object. It is used in the targetConfigs of a LWC. How do I write a test for this class? It didn't seem like you can just

public class Picklist_ContactLookups extends VisualEditor.DynamicPickList{
    String defaultVal = '-- none --';

    public override VisualEditor.DataRow getDefaultValue(){
        VisualEditor.DataRow defaultValue = new VisualEditor.DataRow(defaultVal, defaultVal);
        return defaultValue;

    public override VisualEditor.DynamicPickListRows getValues() {
        VisualEditor.DynamicPickListRows lookupsList = new VisualEditor.DynamicPickListRows();
        List<String> formLookups = Util.findAllLookupsOnContact();
        VisualEditor.DataRow noneValue = new VisualEditor.DataRow(defaultVal, defaultVal);
        for (String lookup : formLookups) {
            VisualEditor.DataRow value = new VisualEditor.DataRow(lookup, lookup);
        return lookupsList;

I tried to call

 VisualEditor.DynamicPickListRows rows = Picklist_ContactLookups.getValues();

from the test and got "Non static method cannot be referenced from a static context: VisualEditor.DynamicPickListRows Picklist_ContactLookups.getValues()". The Util.findAllLookupsOnContact(); already has its own test.

1 Answer 1


You have to instantiate the class to call its member functions.

Picklist_ContactLookups pcl = new Picklist_ContactLookups();
VisualEditor.DynamicPickListRows rows = pcl.getValues();

Then, just make assertions about the class's behavior as you would in any other unit test.

You must log in to answer this question.

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