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
NMackeyNMackey 

apex variables and lookups

I am trying to conditionally assign a value to an apex variable to try and reduce the level of tag soup I'm experiencing writing VF pages to display statements and invoices but running into problems that is making me just move impossible to read and maintain markup elsewhere in my page.

 

I tried using this, so I could refer to fields of the variable 'account' wherever I like. Eclipse gives me message saying 'error' with no text.

 

 

<apex:variable var="account" value="{!IF(CustomObject__c.RecordType.DeveloperName == 'Something', CustomObject__c.Bank_Account__r, CustomObject__c.Other_Bank_Account__r)}" />

 

 

What does work is this:

 

 

<apex:variable var="accountName" value="{!IF(CustomObject__c.RecordType.DeveloperName == 'Something', CustomObject__c.Bank_Account__r.Name, Deal__c.Other_Bank_Account__r.Name)}" />
<apex:variable var="accountSomeOtherField" value="{!IF(CustomObject__c.RecordType.DeveloperName == 'Something', CustomObject__c.Bank_Account__r.someOtherField, CustomObject__c.Other_Bank_Account__r.SomeOtherField)}" />

 

 

But if I have to define a variable like this for every single field, it starts to defeat the purpose!

 

Am I doing it wrong? Any alternate suggestions?