3

I want to assign a variable name in a component through an attribute value of that component. The component uses a controller. When I set the variable name through the content of another variable everything works fine. If I change the value to the content of an attribute of that component it fails saving in the IDE with this error:

Save error: common.apex.runtime.bytecode.BytecodeExecutionContext cannot be cast to common.apex.runtime.impl.Execution

So this very strange error only occurs when certain criteria are met:

  1. You have to use a controller in your component.
  2. The variable name has to be set through an attribute of that component.
  3. You have to save the component through the Salesforce IDE.

The strangest thing about this error is that the component saves without problems through the Salesforce website. As you can see the code is very simple and nothing special so I'm totally clueless about this error.

Component:

<apex:component controller="SObjectSorterController">
    <apex:attribute name="varNameFails" type="String" required="true" description=""/>
    <apex:attribute name="testVal" type="String" required="true" description=""/>
    <apex:variable var="varNameWorks" value="Foobar!"/>

    <!-- This works -->
    <apex:variable var="{!varNameWorks}" value="{!testVal}"/>
    <!-- This does not -->
    <apex:variable var="{!varNameFails}" value="{!testVal}"/>
</apex:component>

Controller:

public with sharing class TestController {}

Has anybody at least some idea as to why this happens and how to circumvent or fix this? The only workaround I came up with so far is saving through the website. But that still isn't a good solution as I'm doing most of my development using Eclipse for obvious reasons. Plus: All pages utilizing this component suffer from the same error when saving through the IDE.

Some insight would be greatly appreciated.

  • metadata version in Dev Console will default to latest version (35); but metadata version in Eclipse will default to Force.com IDE version you installed (? < 35 ?) – cropredy Oct 16 '15 at 23:59
  • Is that a question? I tried different API versions but to no avail. – Semmel Oct 17 '15 at 1:22
  • @Semmel Congrats! You found a bug and/or an undocumented feature. I honestly never expected that you could use expressions in the var attribute (I presumed it had to be literal). Either the feature is not supposed to be supported, but is, or it is, but shouldn't. Depending on the official stance, either the old UI has a bug, or the Tooling API has a bug. I'd suggest contacting salesforce.com support, and make sure they know there's a bug. – sfdcfox Oct 17 '15 at 7:37
3

There's a bug here, but I'm not sure which is the bug, and which is the feature. The IDE apparently (and the Tooling API) only formally supports literal var attributes, not expression var attributes. That means that simply using:

<apex:variable var="varNameFails" value="{!testVal}"/>

Will actually compile successfully in the IDE. Remember that {!...} is telling the server to evaluate a variable, so the original code in the question was actually assigning a value to the variable named in the attribute's value, not varNameFails.

As an example of how you'd use the merge syntax successfully in the UI code, it might be something more like this:

<apex:component controller="SObjectSorterController">
    <apex:attribute name="varNameFails" type="String" required="true" description=""/>
    <apex:attribute name="testVal" type="String" required="true" description=""/>
    <apex:attribute name="param1" type="String" required="true" description="" />
    Before: {!varNameFails}
    <apex:variable var="{!param1}" value="{!testVal}"/>
    After: {!varNameFails}
</apex:component>

Here, assuming param1 is set to varNameFails, the output might be:

Before: Snafu!
After: Foobar!

Unfortunately, what I can't tell you is if this a supported syntax for var. The documentation does not say if this is supported syntax one way or the other.

I suggest you file a case and get a formal answer from a PM, if you can. I'm not sure that dynamic variable names is even a good idea (as demonstrated here, I'm not sure you meant to use expression syntax), but if it was allowed before, it's possible people are using it, so the documentation should reflect the actual technology.

  • Its unfortunate the documentation on this is messed up (developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/…). Instead of <apex:variable var="{!var}" value="{!componentAccount}"/> using the {!...}, it should be as you display here, like so: <apex:variable var="var" value="{!componentAccount}"/>, hours later something so simple makes perfect sense. Thanks again @sfdcfox – Xtremefaith Nov 12 '15 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.