You need to sign in to do that
Don't have an account?
Jesper Klang.
Test Class for VisualEditor.DynamicPickList class
Hi,
I've tried for hours, but cannot seem to figure out how to create a test class for the Apex code below. I'm using it to present a dynamic picklist to a LWC based on values added to a Custom Metadata Type I created.
One error I'm facing when trying to call the class is "Method is not Visible". This is when I'm trying to call the class with a row first like this:
/Jesper
I've tried for hours, but cannot seem to figure out how to create a test class for the Apex code below. I'm using it to present a dynamic picklist to a LWC based on values added to a Custom Metadata Type I created.
One error I'm facing when trying to call the class is "Method is not Visible". This is when I'm trying to call the class with a row first like this:
brandedSectionColorPicklistValues bSCPV = new brandedSectionColorPicklistValues(); VisualEditor.DynamicPickListRows rows = bSCPV.getValues();Here's the full class I'm trying to write a Test Class for:
global class brandedSectionColorPicklistValues extends VisualEditor.DynamicPickList { private VisualEditor.DynamicPickListRows myValues = new VisualEditor.DynamicPickListRows(); brandedSectionColorPicklistValues() { for (Brand_Color__mdt c : [SELECT MasterLabel, Background_Color__c, Font_Color__c FROM Brand_Color__mdt ORDER BY MasterLabel ASC]) { myValues.addRow(new VisualEditor.DataRow(c.MasterLabel, 'background-color:' + c.Background_Color__c + ';border-color:' + c.Background_Color__c + ';color:' + c.Font_Color__c + ';')); } } global override VisualEditor.DataRow getDefaultValue() { return myValues.get(0); } global override VisualEditor.DynamicPickListRows getValues() { return myValues; } }Any help is appreciated!
/Jesper
I still got the same error after changing the myValues variable to public. However, you did lead me in the right direction :) I found the issue, and it was that I hadn't made the class constructor public. I did change the myValues to public as well as you suggested, because it made it easy to add custom values in the Test Class to test, instead of testing the Custom Metadata Type records from the org. Here's the final code and the Test Class that now works great.
Class
Test Class
All Answers
Can you set this line to public instead of private to see if that fixes the error?
private VisualEditor.DynamicPickListRows myValues = new VisualEditor.DynamicPickListRows();
Related:https://salesforce.stackexchange.com/questions/270431/how-to-write-a-test-for-a-visualeditor-dynamicpicklist-class
https://salesforce.stackexchange.com/questions/225787/method-is-not-visible-apex-trailhead-unit-testing-challenge
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
I still got the same error after changing the myValues variable to public. However, you did lead me in the right direction :) I found the issue, and it was that I hadn't made the class constructor public. I did change the myValues to public as well as you suggested, because it made it easy to add custom values in the Test Class to test, instead of testing the Custom Metadata Type records from the org. Here's the final code and the Test Class that now works great.
Class
Test Class