You need to sign in to do that
Don't have an account?
Brianna Bollettieri
Opportunity Screen Modifications based on Stage using Field Sets and Visualforce Pages
Currently I am working on changing our opportunity screen to change the way it is being filled out. This way it follows our sales process. A simple way to put it is that I have created 5 sections on the opportunity screen each representing a different stage. Now what I want to happen is that each time a stage is selected, I would like that section to become available for editing. All new opportunities should begin in the opportunity section, therefore I would like that section to be available for editing, but I want the other sections to be visible but locked from being edited. Then once the next stage is selected, the next section becomes available for editing and the remainder remain visible but locked, etc.
So far I tried testing this with just the opportunity stage. What I did was I created a field set including all the fields in the opportunity section. Then I created a visualforce page. My current issue with this is that it is doing the opposite of what I want. It is blocking the opportunity section (and it is not even visible) until after I save the record. Once the record is saved the opportunity section appears but the entire screen is available for editing. This is my current visualforce page criteria.
<apex:page standardController="Opportunity">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Opportunity">
<apex:repeatvalue="{$ObjectType.Opportunity.fieldsets.opportunityFieldSet}"var="fieldValue">
<apex:Inputfield value="{!Opportunity[fieldValue]}"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Any assistance would be greatly appreciated. Thanks!
So far I tried testing this with just the opportunity stage. What I did was I created a field set including all the fields in the opportunity section. Then I created a visualforce page. My current issue with this is that it is doing the opposite of what I want. It is blocking the opportunity section (and it is not even visible) until after I save the record. Once the record is saved the opportunity section appears but the entire screen is available for editing. This is my current visualforce page criteria.
<apex:page standardController="Opportunity">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Opportunity">
<apex:repeatvalue="{$ObjectType.Opportunity.fieldsets.opportunityFieldSet}"var="fieldValue">
<apex:Inputfield value="{!Opportunity[fieldValue]}"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Any assistance would be greatly appreciated. Thanks!
All Answers
You can use the rendered attribute to display/hide an element. In your case here, you can do something like this: As you can see, based on the StageName = 'New' (you can change it with the real stage name) we display the inputField and hide the outputField. When the StageName is not 'New' anymore, then the outputField will display. Let me know if you need further details.
It is still blocking the Opportunity section from being viewed and edited when I create a new opportunity. It only appears on the screen after I save the opportunity. And it is allowing all sections on the opportunity screen to be edited as I had previously.
You are creating a separate section and a separate fieldset for each StageName, right? Say you have 2 stages, then the code will look like: I am not sure if you want to display section 2 during creation. If you do, then just remove the !ISBLANK(Opportunity.StageName).
Now it is not displaying either section upon creation, only once the record is created. Once the record is created it is working with edit access for each section based on the stage on the screen itself. But when I select the edit button the sections are no longer visible again. This is the current code that's being used.
<apex:page standardController="Opportunity">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Opportunity">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.opportunityFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!!ISBLANK(Opportunity.StageName) && Opportunity.StageName!='Opportunity'}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockSection title="Needs & Requirements">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.nrFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName='Needs & Requirements'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!!ISBLANK(Opportunity.StageName) && Opportunity.StageName!='Needs & Reuirements'}" />
</apex:repeat>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
1. I know you mentioned earlier in order to display section 2 during creation. To just remove the !ISBLANK(Opportunity.StageName). Where would I remove that from? Each time it appears?
2. Is there a way to override standard fields? I have the fields in the field sets so they are still on the screen, but it won't allow me to remove it from the page layout so I was wondering if there was some way to override that.
Thanks for all your help so far, you have been extremely helpful!
1. ISBLANK({!Opportunity.StageName}) is one way of telling us that the Opportunity is brand new. You can use in the section where you want to show/hide your field (not the section). If you want to make the field read-only, display the outputField. And to make the field editable, display the inputField. Hopefully this is pretty clear. If it is not, I can go into details with you.
2. If the field is required, I don't think you can remove it from the layout. Some standard fields, like Name, are required.
3. If you want to leave the previous section to be editable, it will be a little tricky because you will have to add all previous stages in the condition. Something like {!Opportunity.StageName="Stage 1" || Opportunity.StageName="Stage 2"}. However, if your stage starts with a number (e.g.: 1 - Stage 1, 2 - Stage 2), it will be much easier to write the conditions.
Please don't forget to mark my answer if you find it useful. It will help others who are having the same questions. Thanks!
<apex:page standardController="Opportunity">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Opportunity">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.opportunityFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!!ISBLANK(Opportunity.StageName) && Opportunity.StageName!='Opportunity'}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockSection title="Needs & Requirements">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.nrFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{Opportunity.StageName='Opportunity' || !Opportunity.StageName='Needs & Requirements'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{Opportunity.StageName!='Opportunity' || Opportunity.StageName!='Needs & Reuirements'}" />
</apex:repeat>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
<apex:page standardController="Opportunity">
<apex:form >
<apex:pageBlock title="Opportunity" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/> <apex:commandButton value="edit" action="{!Edit}" immediate="true"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.opportunityFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!ISBLANK(Opportunity.StageName) || Opportunity.StageName='Opportunity'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!!ISBLANK(Opportunity.StageName) && Opportunity.StageName!='Opportunity'}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockSection title="Needs & Requirements">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.nrFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName!='Opportunity' && Opportunity.StageName!='Needs & Requirements'}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockSection title="Proposal & Sell">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.psFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements' || Opportunity.StageName='Proposal & Sell'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName!='Opportunity' && Opportunity.StageName!='Needs & Requirements' && Opportunity.StageName!='Proposal & Sell'}" />
</apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockSection title="Closed Won || Closed Lost">
<apex:repeat value="{!$ObjectType.Opportunity.fieldsets.cwclFieldSet}" var="fieldValue">
<apex:inputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName='Opportunity' || Opportunity.StageName='Needs & Requirements' || Opportunity.StageName='Proposal & Sell' || Opportunity.StageName='Closed Won' || Opportunity.StageName='Closed Lost'}" />
<apex:outputField value="{!Opportunity[fieldValue]}" rendered="{!Opportunity.StageName!='Opportunity' && Opportunity.StageName!='Needs & Requirements' && Opportunity.StageName!='Proposal & Sell'&& Opportunity.StageName!='Closed Won' && Opportunity.StageName!='Closed Lost'}" />
</apex:repeat>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
I have a question about record types. There are 2 record types that I want this VF page to apply to as well as the button overrides (New, Edit, and View) to apply to. Do I have to create a separate VF page for this or is there a way to add it to this VF page? Either would work.
Thanks!