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
Miguel Angel Chinchilla B.Miguel Angel Chinchilla B. 

Problem with Dynamic outputText and Test.

Hi Friends,

I have tested a dynamic component for  outputText.

On the Visualforce page show correctly, but where I run my test display the next error:

System.VisualforceException: Invalid value for property label: null

This is the piece of code
dynOutputText = new Component.Apex.outputText();
dynOutputText.value = wrapfee.numCuotaPendiente;                           
dynOutputText.label = Label.label_fee_number;
dynPageBlockSection.childComponents.add(dynOutputText);

​Regards.
EnreecoEnreeco
Have you tried to add some System.debug to watch what's happening in between the lines? 
Miguel Angel Chinchilla B.Miguel Angel Chinchilla B.
Thanks Enreeco for you respond. Let me now to do this.

For resolving the problem I do this.
 
dynOutputText = new Component.Apex.outputText();
dynOutputText.value = wrapfee.numCuotaPendiente;                            
if (!Test.isRunningTest()) {
  dynOutputText.label = Label.label_fee_number;    
}                            
dynPageBlockSection.childComponents.add(dynOutputText);

Regards.
Miguel Angel Chinchilla B.Miguel Angel Chinchilla B.
Hi Enreeco, 

When I add System.debug the error is the next:

System.UnexpectedException: Internal Salesforce Error: 156500021-123953 (-664506234) (-664506234)

​Regards.
EnreecoEnreeco
I've just tryed this simple test class:
@isTest
private class DynamicComponentTest {
	@isTest
    private static void test_1(){
        Component.Apex.PageBlockSection dynPageBlockSection = new Component.Apex.PageBlockSection();
        Component.Apex.outputText dynOutputText = new Component.Apex.outputText();
		dynOutputText.value = 'TEST'; 
  		dynOutputText.label = Label.TestLabel;                                
		dynPageBlockSection.childComponents.add(dynOutputText);
        
    }
}
And I get the same error!
This seems an issue, but I haven't found anything on the known issues or stackoverflow or forums.
The following whould work:
@isTest
private class DynamicComponentTest {
	@isTest
    private static void test_1(){
        Component.Apex.PageBlockSection dynPageBlockSection = new Component.Apex.PageBlockSection();
        Component.Apex.outputText dynOutputText = new Component.Apex.outputText();
		dynOutputText.value = 'TEST'; 
  		//dynOutputText.label = Label.TestLabel;                                
        dynOutputText.expressions.label = '{!$Label.TestLabel}';                                
		dynPageBlockSection.childComponents.add(dynOutputText);
    }
}
Anyway I suggest you to open a case to the support.
It seems like the test engine cannot access the Label value.

Bye
E.

 
Miguel Angel Chinchilla B.Miguel Angel Chinchilla B.
Thanks a lot, Enreeco.