Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

In a controller I have two values:

public List<String> StringValue {get; set;} 

public List<String> ListValue {get; set;} 

The ListValue is initialized in the constructor and several strings are added. At this point in value I can refer to these with {!StringValue} and {!ListValue[1]} in a VisualForce page. The list one, in particular, is the focus - I can even add pseudo-constants (getters) as indexes, making {!ListValue[nameIndex]} a valid reference.

However, I've run into an exception when trying to set a list value instead of a simple string value.

<apex:param value="123" assignTo="{!ListValue[1]}" /> 

The exception is java.lang.ClassCastException: java.lang.String cannot be cast to common.formula.FormulaFieldReference

I think I understand the basics of the problem - Salesforce can't create a setter reference that includes an index parameter (meaning only setters that take a single parameter can be referenced).

Is there any way around this, or do I just have to create a massive amount of ListValue1, ListValue2 variables and associated code?

1 Answer

0 votes
by (32.1k points)
edited by

This will avoid you to create dozens of variables.

<apex:param value="1:123" assignTo="{!smartAssigner}" />

Then in your controller:

public void setSmartAssigner(String myval) { // parse the colon, set list value appropriately.

Hope you got the idea.

Look at the Salesforce Course provided by Intellipaat!

Browse Categories