1

I was looking back in the old code some developer created but already left and have no idea why he had to duplicate the buttons :

<apex:pageBlock id="PageBlock" title="Template">
    <apex:outputPanel rendered="{!$User.UIThemeDisplayed =='Theme4d'}">
        <div style="margin-left: 32%;">
            <apex:commandButton value="Back" action="/apex/GenerateLAF" immediate="true" onclick="statusTopDivStart();" />
            &nbsp;&nbsp;
            <apex:commandButton action="{!SaveLAF}" onclick="disableOnSubmit(this);" value="Save" />
            <apex:commandButton action="/home/home.jsp" immediate="true" value="Cancel" rendered="{! $User.UIThemeDisplayed != 'Theme4d' }" />
            <apex:commandButton action="/lightning/page/home" immediate="true" value="Cancel" rendered="{! $User.UIThemeDisplayed == 'Theme4d' }" />
        </div>
    </apex:outputPanel>

    <apex:pageBlockButtons rendered="{!$User.UIThemeDisplayed !='Theme4d'}">
        <apex:commandButton action="/apex/GenerateLAF" immediate="true" onclick="statusTopDivStart();" value="Back" />
        <apex:commandButton action="{!SaveLAF}" onclick="disableOnSubmit(this);" value="Save" />
        <apex:commandButton action="/home/home.jsp" immediate="true" value="Cancel" rendered="{! $User.UIThemeDisplayed != 'Theme4d' }" />
        <apex:commandButton action="/lightning/page/home" immediate="true" value="Cancel" rendered="{! $User.UIThemeDisplayed == 'Theme4d' }" />
    </apex:pageBlockButtons>
</apex:pageBlock>

This displays the visual as below which looks identical :

enter image description here

Can someone enlighten me what scenarios I should be using for these different functions?

2

If you pay a bit of attention to the rendered section of,

<apex:outputPanel rendered="{!$User.UIThemeDisplayed =='Theme4d'}">

you'll realise that the commandButton inside is contradicted

<apex:commandButton action="/home/home.jsp" immediate="true" value="Cancel" rendered="{! $User.UIThemeDisplayed != 'Theme4d' }" />

and makes the following rendered part redundant

<apex:commandButton action="/lightning/page/home" immediate="true" value="Cancel" rendered="{! $User.UIThemeDisplayed == 'Theme4d' }" />

Something quite similar happens with the part on pageBlockButtons.

My first guess, having a look at the "quality" of the code would be that the reasons are either a newbie DEV or iterations and modifications over time (quick-fixes) that do not pay attention to the "sense" of what it was left behind.

But it could have been a workaround for a bug back in the days or he just wanted to have full control over how its displayed for some automation, to control the margins, etc. and don't depend on the CSS styling of SF so much.

For this, and many other reasons, it is important to make sure that devs comment the code, even more when doing things "outside" the standard / implementing workarounds.

| improve this answer | |

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.