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
AndrefecAndrefec 

Dynamic Visualforce Component Error on Test Method

Hello,

 

I have the next code created:

 

Component.Apex.outputText firstNameField = new Component.Apex.outputText();
firstNameField.value = opp.Primeiro_Nome__c;
firstNameField.label = 'Primeiro Nome';
firstNameField.id = 'firstNameField';

 

 

And it will result on a dynamic Pageblock on a visualpage.

 

Opening it on a page everything is ok, but when i run the test class it give me the next error:

" System.VisualforceException: Invalid value for property label: null"

 

What can i do? I need to complete my test class to move to production.

Thank you

Taiki YoshikawaTaiki Yoshikawa

Hi,

 

Probably...You need to set a value in the opp.

 

 

Sample__c opp = new Sample__c();
opp.Primeiro_Nome__c = 'TEST';

Component.Apex.outputText firstNameField = new Component.Apex.outputText(); firstNameField.value = opp.Primeiro_Nome__c; firstNameField.label = 'Primeiro Nome'; firstNameField.id = 'firstNameField';

 

AndrefecAndrefec

Thank you for the reply

 

The problem is on firstNameField.label, because if i coment that the test pass.

 

 

Taiki YoshikawaTaiki Yoshikawa

I did not know the cause of the error.
There was no error in this method.

 

private Component.Apex.InputText getAccountSite() {
	Component.Apex.InputText dynamicInputText = new Component.Apex.InputText();
	dynamicInputText.expressions.label = '{!$ObjectType.Account.Fields.Site.Label}';
	dynamicInputText.expressions.value = '{!account.Site}';
	dynamicInputText.id                = 'AccountSite_Id';
	return dynamicInputText;
}

 

 

Ian TaiteIan Taite
Did you find the solution to this problem, as I too have a problem running APEX code that creates a component dynamically in a test that fails with "System.VisualforceException: Invalid value for property label: null". The code works fine when run from outside a test environment, but fails when called from a test.