[SalesForce] How to hide fields in detailpage when saved in a Visualforce page

enter image description here

When i save the record the % fields also showing in detail page. below is the page

<apex:page standardController="opportunity">
<apex:includeScript value="{!$Resource.jquery}"/>

<apex:sectionHeader title="opportunity Edit" subtitle="{!opportunity.name}"/>
<apex:form>
 <apex:pageBlock title="opportunity Edit" mode="edit">
  <apex:pageBlockButtons location="top">
   <apex:commandButton value="Save" action="{!save}"/>
   <apex:commandButton value="Save & New" action="{!save}" />
   <apex:commandButton value="Cancel" action="{!cancel}"/>
  </apex:pageBlockButtons>
  <apex:pageBlockButtons location="bottom">
   <apex:commandButton value="Save" action="{!save}"/>
   <apex:commandButton value="Save & New" action="{!save}" />
   <apex:commandButton value="Cancel" action="{!cancel}"/>
  </apex:pageBlockButtons>

  <apex:pageBlockSection title="Opportunity Information" columns="2">
   <apex:inputField value="{!opportunity.Name}" required="true"/>
   <apex:inputField value="{!opportunity.Type}" required="false"/>
   <apex:inputField value="{!opportunity.CloseDate}"/>
   <apex:inputField value="{!opportunity.StageName}"/>

   <apex:inputField value="{!opportunity.LeadSource}" required="false"/>
   <apex:inputField value="{!opportunity.AccountId}" required="false"/>
   <apex:inputField value="{!opportunity.IsPrivate}" required="false"/>
   <apex:inputField value="{!opportunity.CampaignId}" required="false"/>            
  </apex:pageBlockSection>

  <apex:pageBlockSection title="Contract Information" columns="1">

   <apex:inputField value="{!opportunity.Funding_Type__c}" id="type" onchange="fund(this)"/>                 

   <apex:inputField value="{!opportunity.X60_Minute_Funding_Amt__c}" html-class="dollor"  required="false" id="id1"/>
   <apex:inputText value="{!opportunity.X60_Minute_Funding__c}" html-class="percentage" required="false" id="id5"/>

   <apex:inputText value="{!opportunity.X3_Hour_Funding_Amt__c}" html-class="dollor" required="false" id="id2" />
   <apex:inputField value="{!opportunity.X3_Hour_Funding_1__c}" html-class="percentage" required="false" id="id6"/>

   <apex:inputText value="{!opportunity.Next_Day_Funding__c}" html-class="dollor" required="false" id="id3"/>
   <apex:inputField value="{!opportunity.Next_Day_Funding_Perc__c}" html-class="percentage" required="false" id="id7"/>

   <apex:inputText value="{!opportunity.Same_Day_Funding_Amt__c}" html-class="dollor" required="false" id="id4"/>
   <apex:inputField value="{!opportunity.Same_Day_Funding_1__c}" html-class="percentage" required="false" id="id8"/>
  </apex:pageBlockSection>
 </apex:pageBlock>
</apex:form>

 <script type='text/javascript' src= '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>          

        <script language="javascript">
            $(function() {        
                $('select.RemoveNone option[value=]').remove();    

            });
        </script> 

      <script type="text/javascript">
          j$ = jQuery.noConflict();
           changeDisplay(".percentage", false);
               function changeDisplay(type, show){

    if(show){
        j$(type).show();
        j$(type).each(function(){
            j$("label[for='" + this.id + "']").show();
        });
    } else {
     j$(type).hide();
        j$(type).each(function(){
            j$("label[for='" + this.id + "']").hide();
        });
    }
}

function fund(s){

    if(s.value == "$"){
        changeDisplay(".dollor", true);
        changeDisplay(".percentage", false);
    }else
    if(s.value =='%'){
        changeDisplay(".dollor", false);
        changeDisplay(".percentage", true);
    }else{
        changeDisplay(".dollor", true);
        changeDisplay(".percentage", true);
    }
}

 </script>
</apex:page>

Best Answer

As you are using the standard controller for the opportunity sobject, when you save the record you will be redirected to the standard record view page. The fields displayed on this page are not related to any Visualforce pages, rather they are configured using the page layout editor, information on which can be found at:

https://help.salesforce.com/HTViewHelpDoc?id=customize_layoutcustomize_pd.htm&language=en_US

When you create custom fields, the default behaviour is usually to add the field to the end of the first two column section on the page, although this can change depending on the field type, more information at:

https://help.salesforce.com/apex/HTViewHelpDoc?id=adding_fields.htm&language=nl

If you don't want the percentage fields to appear in the record view, simply edit the page layout and remove them. If you want to allow users to flip between percentage and dollar amounts, then you'll have to override the standard view page with a Visualforce page that provides this functionality.

Related Topic