0

I'm new to this so please try to be extra patient with me :) Trying to display an message in the Account layout based on the Account name field. So what I've got working so far is the error message. Now, the problem is that if the message is not displayed (because rendered evaluated to false), it leaves a gaping blank section where the pageblock is. How can I make that section collapse if rendered equals to false? Found a post here that suggested using twistSection but didn't work.

Here's my code:

<apex:page standardController="Account"
           sidebar="false"
           showHeader="false"
           showChat="false">
<apex:pageBlock id="block1" rendered = "{!Account.Name = 'Test'}">
    <apex:pageBlockSection id="section1" columns="1" collapsible="true">
        <apex:pageMessage summary="Message" 
                  severity="warning" 
                  strength="3" />
    </apex:pageBlockSection>

<script> twistSection(document.getElementById('{!$Component.block1.section1}').getElementsByTagName('img')[0]) </script>
</apex:pageBlock>
</apex:page>

Thanks!

3
  • 1) Twistsection won't work because the pageBlockSection is never rendered initially so it doesn't exist for the javascript to find; 2) did you try putting the rendered= on a surrounding apex:outputPanel (surrounding to the pageBlock)? – cropredy Jul 7 '15 at 22:47
  • Just tried putting outputPanel before pageblock (and moved rendered there) but still the same thing. @crop1645 – jekism Jul 7 '15 at 23:07
  • post an image of the rendered page annotated by what you want it to look like – cropredy Jul 7 '15 at 23:14
1

Change {Account.Name = 'Test'} to {!Account.Name == 'Test'}. You're also missing a " after your rendered=.

When accessing fields make sure your brackets start with {!.

3
  • 1
    For formulas and Visualforce expressions, = and == are identical. It's acceptable to simply write {!Account.Name='Test'}. You cannot assign a value using this syntax. – sfdcfox Jul 7 '15 at 21:16
  • The missing ! and quote at the end are typo errors, i have it as {! in the actual code. Sorry. – jekism Jul 7 '15 at 21:17
  • @sfdcfox Ah, thank you! I didn't know that. – user19038 Jul 7 '15 at 21:18

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.