Having an issue with my visualforce override - salesforce

I've recently created an override within Salesforce for the default "New" button on the Opportunity tab using the following:
Everything is working perfectly, but when I created a new custom button on the contact object and replaced the original "New" one from the related list section which is the only place my company wants Opps created, this still fires and displays the message.
What am I missing so that my override is not triggered by the "New Opportunity" button I've replaced the original "New" button in the Opportunity Related Lists section of the Contact page layout?
<apex:page standardController="Opportunity">
<apex:includeLightning />
<apex:form >
<apex:pageBlock >
<apex:pageMessage summary="Create Opportunity from Contact record" severity="info"
strength="3" />
<apex:pageMessages />
</apex:pageBlock>
</apex:form>
</apex:page>

Related

Return URL to redirect list view which is visualforce page

i have 1 custom object test_2__c and i created tab of it.
i have overridden this tab with a visual force page (tab redirect).
<apex:page action="{!URLFOR($Action.Test_2__c.List,$ObjectType.Test_2__c)}"/>
and i have 1 list button called "New". it is a button URL.
{!URLFOR($Action.Test_2__c.New)}?returnURL={/apex/tabredirect}
so when i click on this button from list view it opens an edit page for inserting a new record (The standard salesforce edit page, i didn't override it).
Now I am facing an issue here, when i click on "cancel" button from edit page, it remains on that page, i want to redirect it to list view which i have overridden with the visual force page.
Have you tried adding a cancelURL parameter to the URL? For example, you can send the user to a new visualforce page on cancel with the following parameter
...&cancelURL=/apex/YourApexPageNameHere

How to hide sections of page layout based off Owner

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>

disable the working of save button

I have done a VF page in this pages controller. I have written a query to get some record. If the condition is false then an error message is shown. If the error message is shown then I want to disable the working of the save button.
Is it possible to enable the working of save button, or disable a save button? In Apex code.
The disabled attribute of an <apex:commandbutton> can be set to enable/disable a button. Setting this attribute to a bound Apex variable would allow you to control whether or not the button is enabled in your Apex Controller or Extension.
Example Visualforce markup:
<apex:commandbutton action="{!save}" value="Save" id="theButton" disabled="{!myApexBooleanVariable}" />
Example Controller or Extension Apex code:
public Boolean myApexBooleanVariable {get;set;}

Custom Button on new Opportunity Page that links to Visualforce Page on Save

I've encountered a customers sandbox where the standard "Save" and "Save & New" buttons have been replaced by a "Save & Add Brand" button on the standard new opportunity page. They have renamed Opportunity Line Items as Brands and have renamed the Products tab as such.
When pressed, the button saves the Opportunity (after validation of required fields etc...) and then redirects the user to a custom Visualforce page for entering the Brand details. The Visualforce Page they arrive on is configured as the override for Opportunity Product standard button AddProduct.
How has the "Save & Add Brand" button been added to the New Opportunity page to replace the standard buttons?
I need to add some additional buttons but can't find where it has been configured.
Under Customize > Opportunities > Buttons and Links > Standard Buttons and Links New is not showing any override. Also, if I add ?nooveride=1 to the URL I get the same page with the custom button. Edit has been overridden but that Visualforce page isn't the one being displayed to new (as expected).
There is no Detail Page Button on Opportunity with a label corresponding to this button.
Go to Setup > Customize > Opportunities > Settings and disable "Prompt users to add products to opportunities"
Details: Salesforce Help & Training: Prompting for Products on Opportunities
Note: If enabled, replaces the Save button with a Save & Add Product
button [on] the opportunity creation page.

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.

Resources