You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Make field read only based on user
Hello,
I have a apex component where I need to make some of the fields read only based on the logged in user.
If(($User.FirstName + " " +$User.LastName) != Text(Buyer__c)
make the agent field read only?
Thanks,
P
I have a apex component where I need to make some of the fields read only based on the logged in user.
<apex:outputfield value="{!Account.Agent__c}" />Can I use an if statement like
If(($User.FirstName + " " +$User.LastName) != Text(Buyer__c)
make the agent field read only?
Thanks,
P
if it helps please mark as correct so the question can be closed.
Thanks,
P
disabled="{!$User.FirstName + " " +$User.LastName != 'Text(Buyer__c)'}"
Please like and mark as correct if it helps you solve your issue.
good luck
P
Post the entire code to see.
Please if we are making progress like the comments in which you could advance, this encourage us to keep helping
Thank you,
P
If I use this syntax it deploy:
But If I add the last name it fails So we are getting close
Thanks,
P
if not maybe you can create a field in your controller and join the firstName and LastName so you online check that field like FullName.
Please like the comments in which you make progress, and if you get your question answered please mark as the best
When I added this to the VF page I get this error: Is it the way I am referencing it in the Controller?
Thanks,
P
And in the definition use only usr = [SELECT ID, Name FROM User WHERE ID = :UserInfo.getUserId()];
Something like this:
Thanks for your help.
P
For the validation use: <apex:inlineEditSupport disabled="{!usr.Name == (acc.Buyer__c)}"/>
This is assuming acc is the variable where you are saving the Account information.
Also if the acc.Buyer__c is not what you expect try using Text(acc.Buyer__c)
If not please show me the debug value for Buyer__c and what you want to show.
The Buyer__c is a picklist field with a few users names so I am not querying the field in the controller. So if the value in the picklist is Agustin B and I am access the the VF pagge I should not be able to edit the Agent field. I just thought of something. The code resides in an apex component and not directly on the VF page. Maybe that is the issue?
If the apex component is calling the vf you can pass parameters, if you have the Buyer__c there then pass it as a parameter. If not you could query tan information into a Account acc variable.
Let me know.