How to hide sections of page layout based off Owner - salesforce

I'm new to Salesforce and I was looking into making a page layout for Leads/Contacts/Accounts to have special owner visibility.
I have the detail page looking as needed using Standard Salesforce page layouts, but am wondering how can I show or hide a section of the layout based on whether the viewing User is the Owner of the record.
Desired Scenario:
Record R is owned by User A. Detail Page for Record R is a Standard Salesforce Page Layout with 2 sections: one section containing Contact info (that ONLY User A, the owner, can see), and one section containing additional info (that ALL users can see).
I have reviewed the documentation and from what I can see the only way is to either build a custom controller or extension. Is this the only way and if so, does anyone have a good walkthrough in changing only a section of a page layout rather than creating an entirely new page?

Your best option (Approach 1) is to separate your fields into FieldSets (see Working with Field Sets in Visualforce ) and then override the detail page using a Visualforce Page that uses those FieldSets to determine which fields to display AND only shows certain FieldSets if the User viewing the page is the Owner of the record. This approach requires no custom controller / extension, allows you to hide various sections of your page to non-Owners, and allows you (or another admin) to modify the fields in each section going forward using the drag-and-drop FieldSet editor, which is very similar to the Drag-and-Drop Page Layout editor.
Another method (Approach 2) that also requires no custom controller / extension would be to create a Visualforce Page that contains the fields you only want to show to the owner, and then only render these fields if the running user is the record owner. YOu can then add this Visualforce Page to your Page Layout. The reason I don't recommend this approach is that it is a pain to get the styling of the fields in this Page to match up with the rest of the standard page layout.
Just FYI, there is no straightforward way (read: without JavaScript hacks) to show/hide sections of a standard Page Layout without using Visualforce.
APPROACH 1:
<apex:page standardController="Contact">
<!-- Fields everyone should see -->
<!-- (stored in the 'FieldsEveryoneSees' fieldset) -->
<apex:repeat value="{!$ObjectType.Contact.FieldSets.FieldsEveryoneSees}" var="f">
<apex:outputField value="{!Contact[f]}" /><br/>
</apex:repeat>
<!-- Fields only the Owner should see -->
<!-- (stored in the 'OwnerOnlyFields' fieldset) -->
<apex:repeat value="{!$ObjectType.Contact.FieldSets.OwnerOnlyFields}" var="f"
rendered="{!$User.Id == Contact.OwnerId}">
<apex:outputField value="{!Contact[f]}" /><br/>
</apex:repeat>
</apex:page>
APPROACH 2:
<apex:page standardController="Contact" showHeader="false" sidebar="false">
<apex:outputPanel rendered="{!Contact.OwnerId == $User.Id}">
<!-- Fields only the Owner should see -->
<apex:outputField value="{!Contact.LastModifiedDate}"/>
<!-- etc... -->
</apex:outputPanel>
</apex:page>

Related

Tags component for Salesforce Visual Force page on custom object

I have enabled Tags on a custom object, which has a Visual Force page override for edit/view in place of the standard page layouts.
Is there way to add the standard Tags component to the VF pages, or do I have to manually code something ?
Use Topics instead of tags .A VF widget can be added as shown below
<apex:page> <topics:widget entity="0D5x00000009Fhc" customUrl="mywebsite/TopicViewTestPage? topicId="/>
</apex:page>

How to hide the VF page in Opportunity View in salesforce

i am using one Vf page in opportunity page and and have one checkbox above the VF page as
Approverd ---------- checkbox
....................................................Visual force page..........................................
Data
.............................................................................................................................
what i did is when check box is uncheked the vf page or view that show above is hide on save button click that work perfectly.but the blank space is there in the place of VF page .
I hope you got what I mean.
You can create 2 different opportunity page layouts. The first layout with your checkbox the second with the visualforce page. You assign the 2 page layouts to different RecordTypes. Your checkbox can trigger a workflow that is changing the record type and the pagelayout.
The next option is to use javascript to hide the section, but this is not reliable.

Add a label custom field in Salesforce Page

I'm trying to put a checkbox in a salesforce page but the problem is that the required message is more than 40 characters so it doesn't fit in the checkbox label (40 character max)
I tried adding two custom fields on top of the checkbox but the problem that these fields even though if they are read only the user can edit there content(text(255)) or not be able to see them(formula(text)) in edit mode.
Is there any way I can do that without creating a custom page and appending it in the page?
It isn't an ideal solution but you could create a new section on your page layout which will allow more text than a label to be displayed. Then only put your confirmation check box field in that section.
That will affectively give you the long label description you are looking for.
You can create a very simple Visualforce page:
<apex:page standardController="Account" showHeader="false" sidebar="false">
I confirm that the new account is open
</apex:page>
Set the controller to your object; I use "Account" here.
You then insert the Visualforce page directly into the page layout, just like you would a field.
It sounds like you need visualforce or S-Controls (now deprecated)
An alternate is to make a text box and prepopulate it with the info, but I think that too would need those technologies
If you come up with a solution to this- let me know.

Is it possible to add style to a field in Salesforce?

I have a situation where I need to convert input text to upper case. As soon as we type some text in the input field it needs to convert it to Upper case.
We have following css style for this:
style="text-transform: uppercase"
Using this style, text is entered in Upper case automatically so we don't need to do anything extra, but there is no option in Salesforce to add style to a field.
Is there any way to accomplish this?
Unfortunately, there isn't an easy way to add a CSS style to a field appearing on a Standard Page Layout in edit mode. However, there are some options (listed below) you may want to explore.
Visualforce
You can add a style attribute to an [inputtext] in Visualforce (http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inputText.htm) or inputfield component.
<apex:inputtext value="{!Widget__c.Name}" style="text-transform:uppercase;" />
To add a CSS class instead, you can use the styleClass attribute. I believe this affects only the display of the text data, though. To make sure the value is uppercase when saved to the database, use this JavaScript on the onkeyup attribute (below).
<apex:inputtext value="{!Widget__c.Name}" style="text-transform:uppercase;" onkeyup="var u=this.value.toUpperCase();if(this.value!=u){this.value=u;}" />
Standard Page Layout
Option 1: Embedding a Visualforce Page in a Standard Page Layout
To do this on a Standard Page Layout, you could create a Visualforce Page for the field you would like this functionality on. This however will show up on View of the record only. It will not be visible on Edit.
The Visualforce Page would look like this (where Widget__c is replaced by the sObject you're working with):
<apex:page standardController="Widget__c">
<apex:form id="WidgetForm">
<apex:actionFunction name="SavePost" action="{!save}" rerender="WidgetPanel" status="str" />
<apex:outputpanel id="WidgetPanel">
<apex:inputtext id="WidgetName" value="{!Widget__c.Name}" style="text-transform:uppercase;" onkeyup="var u=this.value.toUpperCase();if(this.value!=u){this.value=u;}" />
<apex:commandbutton value="Save" styleClass="btn" onclick="SavePost();" />
<apex:actionStatus startText="Loading..." stopText="" id="str"> </apex:actionStatus>
</apex:outputpanel>
</apex:form>
</apex:page>
Then on the Page Layout, click the Visualforce Pages category underneath Fields and Buttons, and add your Visualforce page to your Page Layout by dragging the Visualforce Page component to the Layout. Be sure to configure the height of it by clicking the wrench in the top right of the new Visualforce Page component.
Option 2: Use JavaScript on a Standard Page Layout with a Sidebar Component
Another, more complicated, option for working with a Standard Page Layout would be to add a Home Page Component on the Sidebar that contains JavaScript. This option requires a fair understanding of JavaScript (or jQuery a JavaScript library). The JavaScript could then find the field, add the text-transform:uppercase; style to it, and bind a function to the keyup event to convert all inputted characters to uppercase (element.value.toUpperCase();). For more information on this method, check out Tehnrd's blog post on adding a sidebar component for JavaScript. He uses this method to show and hide buttons on Standard Page Layouts, but it could be modified to suit your purposes.

salesforce: How do I set custom tag homepage?

I've created custom object and custom tab (label text="order").
Now my header looks like below just like everyone can do.
[home]__[customer]__[order]
And when I click on "order" tab, I am redirected to home page of "order"
The "order" homepage has:
view (which goes to search feature)
recent record
My question is how do I change the layout of this homepage? I've look though entire site and documentations but seems like it is not possible. The only option I have is to create brand new visualforce page and set that page as default homepage for the "order" tab.
No, you can't change the contents of a default tab homepage beyond the limited controls under Setup. You would have to create a new Visualforce page and replace the page all together; however, with an enhancedList, you can get the basics down without too much coding, like this:
<apex:page>
<apex:enhancedList type="Account" height="500" />
</apex:page>
This would just show the standard Account list views on the tab (which could have Recent Items), but you could spruce things up with other components or make the list view customized with a set controller.

Resources