1

I am relatively new to Visualforce. I am trying to change my Opportunity Edit page with a visualforce page that has rendering capabilities. Where I am getting stuck at right now is that I have some fields on there that managers can see, but normal sales people cannot.

Right now, I have the field listed on my page, and the Opportunity New and Edit buttons linked to the new visualforce page. If I create a new record while logged in as a Manager, I can see the layout exactly as I have it set. However, if I log in as a normal sales person, the fields shift because they don't have access to see the field.

How can I make the visualforce page keep the spacing and arrangement of fields so that when someone is unable to see the field, there is a blank space, and the layout doesn't shift?

Here is a snippet of the code that I have.

I edited this from the initial post to update it to show what I have now. I am still not sure if what I am doing on the Opportunity.Audited__c row and the blank row after is the best method for this.

<apex:page standardcontroller="Opportunity" >
    <apex:form >
        <apex:pageBlock title="Opportunity Edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="Detail" title="Opportunity Detail" columns="2">
                <apex:outputfield Value="{!Opportunity.OwnerId}" />
                <apex:inputField value="{!Opportunity.CloseDate}" />
                <apex:inputfield Value="{!Opportunity.Name}" />
                <apex:inputField value="{!Opportunity.Contract_Expiration__c}" />
                <apex:inputfield Value="{!Opportunity.AccountId}" />
                <apex:inputField id="stage" value="{!Opportunity.StageName}" >
                        <apex:actionSupport event="onchange" rerender="Stage1,Stage2,Stage3,Stage4,Weartest,Bid" />
                </apex:inputField>
                <apex:outputfield Value="{!Opportunity.Opportunity_Total__c}" />
                <apex:inputField value="{!Opportunity.Reason__c}" />
                <apex:inputfield Value="{!Opportunity.Audited__c}" rendered="{!$ObjectType.Opportunity.fields.Audited__c.accessible=True}"/>
                <apex:outputlabel Value="" rendered="{!$ObjectType.Opportunity.fields.Audited__c.accessible!=True}"/>
                <apex:inputField value="{!Opportunity.Who_Won__c}" />
            </apex:pageBlockSection>

The line is the field in this section that is visible only to Managers. Their screen shows this lined up as 2 columns. However, on the sales person record, the Who Won field is moved over to the left.

I have tried looking online, but apparently my googling skills are lacking, probably because I am not searching for the correct phrase or word. If someone knows of a place that can point me in this direction, I would be most appreciative.

Thanks.

0

1 Answer 1

1

Have you tried looking into field set route, this is one of the cleanest route I can think of.

You can do a lot of rendering, hiding workarounds with the way you are doing now or look at field set route which gives you a cleaner option.

http://www.sfdcpoint.com/salesforce/fieldset-visualforce-page-salesforce/

eg:

<apex:page standardcontroller="Opportunity" >
    <apex:form >
        <apex:pageblock >

          <!--fields for sys admin-->    
          <apex:pageBlockSection title="Account detail" rendered="{!$Profile.Name = 'System Administrator'}">
             <apex:repeat value="{!$ObjectType.opportunity.fieldsets.sysadmin_fieldset}" var="fieldValue">
                 <apex:Inputfield value="{!opportunity[fieldValue]}"/>
             </apex:repeat>
          </apex:pageBlockSection>

           <!--fields for read only--> 
           <apex:pageBlockSection title="Account detail" rendered="{!$Profile.Name = 'Read only'}">
             <apex:repeat value="{!$ObjectType.opportunity.fieldsets.readonly_fieldset}" var="fieldValue">
                 <apex:Inputfield value="{!opportunity[fieldValue]}"/>
             </apex:repeat>
          </apex:pageBlockSection>

           <!--fields for solution manager--> 
           <apex:pageBlockSection title="Account detail" rendered="{!$Profile.Name = 'solution manager'}">
             <apex:repeat value="{!$ObjectType.opportunity.fieldsets.solnmanager_fieldset}" var="fieldValue">
                 <apex:Inputfield value="{!opportunity[fieldValue]}"/>
             </apex:repeat>
          </apex:pageBlockSection>
      </apex:pageblock>
    </apeX:form>
</apex:page>

Update:

Try updating this line to:

this way if the user can access the field the field is displayed or hidden

<apex:inputfield Value="{!Opportunity.Audited__c}" rendered="{!IF($ObjectType.Opportunity.fields.Audited__c.accessible,True,False)}"/>
4
  • Thank you for the link. I took a look at it, and it appears that this is more for groups of fields. I am just looking for 1 field that will need to be displayed or not without shifting the rest of the fields. Based on your code, I will need to add 2 rows to my page for this; one row to display my Audited__c field for those that can see it, and one row to display a blank space to keep the columns and cells aligned properly.
    – smckitrick
    Commented Sep 25, 2015 at 20:00
  • you can simply use rendered="some condition" and hide or display the field then
    – Rao
    Commented Sep 25, 2015 at 20:43
  • That's what I have right now. I was hoping that I could do this all in 1 line instead of 2.
    – smckitrick
    Commented Sep 25, 2015 at 20:56
  • look at the update
    – Rao
    Commented Sep 25, 2015 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .