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
Subrahmanyam KonathlapalliSubrahmanyam Konathlapalli 

How to disable a custom button in visualForce page fro particular user

Best Answer chosen by Subrahmanyam Konathlapalli
Khan AnasKhan Anas (Salesforce Developers) 
Hi Subrahmanyam,

Greetings to you!

You can disable a custom button using a rendered attribute in the visualforce page.

For User:
<apex:page >
    <apex:form>
    	<apex:pageBlock>
        	<apex:commandbutton value="Button" 
                                title="Click Me" 
                                rendered="{!$User.Username == 'khananasrehmani@sambodhi.com'}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

For Profile:
<apex:page >
    <apex:form>
    	<apex:pageBlock>
        	<apex:commandbutton value="Button" 
                                title="Click Me" 
                                rendered="{!IF($Profile.Name =='System Administrator'||$Profile.Name =='Sales Manager', true , false)}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
OR
<apex:page >
    <apex:form>
    	<apex:pageBlock>
        	<apex:commandbutton value="Button" 
                                title="Click Me" 
                                rendered="{!$Profile.Name == 'System Administrator'}"
        </apex:pageBlock>
    </apex:form>
</apex:page>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Subrahmanyam,

Greetings to you!

You can disable a custom button using a rendered attribute in the visualforce page.

For User:
<apex:page >
    <apex:form>
    	<apex:pageBlock>
        	<apex:commandbutton value="Button" 
                                title="Click Me" 
                                rendered="{!$User.Username == 'khananasrehmani@sambodhi.com'}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

For Profile:
<apex:page >
    <apex:form>
    	<apex:pageBlock>
        	<apex:commandbutton value="Button" 
                                title="Click Me" 
                                rendered="{!IF($Profile.Name =='System Administrator'||$Profile.Name =='Sales Manager', true , false)}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
OR
<apex:page >
    <apex:form>
    	<apex:pageBlock>
        	<apex:commandbutton value="Button" 
                                title="Click Me" 
                                rendered="{!$Profile.Name == 'System Administrator'}"
        </apex:pageBlock>
    </apex:form>
</apex:page>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Subrahmanyam KonathlapalliSubrahmanyam Konathlapalli
Hi Anas,

Thank u so much it helped me.