0

I am currently designing a page layout and it is not finalized. I am trying to make it so that only when out of warranty is checked that two fields will pop up. Those two fields are Payment and Payment Received. They do pop up originally, however after you enter the value and save it disappears. It looks like below. It starts like this (which is what I want):

and then it becomes like this after you click save. enter image description here.

Is there a way to make the fields render without using visual force? I assume I have this current problem because I am currently using an apex form. But according to the error I received, buttons are only allowed if it is a form. If I have to use visual force is there a way for that section to not disappear?

Here is my code for the Visual Force part:

<apex:page standardController="Service_Case__c" >
    <apex:form >
  <apex:pageBlock title="Service Case Summary">

        <apex:pageBlockSection title="Service Case Stuff"  columns="2">
              <apex:outputField value="{!Service_Case__c.Name}"/>
              <apex:outputField value="{!Service_Case__c.LGFProduct__c}"/>
        </apex:pageBlockSection>

            <apex:pageBlockSection title="Payment" columns="2" rendered="{!if(Service_Case__c.Out_of_Warranty__c, true, false)}">
              <apex:outputField value="{!Service_Case__c.Payment__c}"/>
                <apex:inlineEditSupport disabled="false"/>
              <apex:outputField value="{!Service_Case__c.Received_Payment__c }"/>
                <apex:inlineEditSupport disabled="false"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Also this might count as another question and if needed I will separate it, but for some reason LGFProduct never shows up. It is in a look-up relationship with Service Case. If I add the extension of LGFProduct will it appear? Formerly it used to show the ID I believe but now it shows nothing.

0

First, try adding the showHeader=false and sidebar="false" to your Page tag.

<apex:page id="Purchase" showHeader="false" sidebar="true">

This will remove all of the clutter and leave you with the fields.

Also, when you click save do not return a pagereference, simply return null or make the method void and rerender the page (if needed). I am assuming without seeing your code that you are redirecting the inline page to the full record view when what you really want is to just show the fields.

the above will require a custom controller to override the save method, for example:

 public class myPageController{

    public Case theCase {get;set;}

    public myPageController(ApexPages.standardController con){

       theCase = (Case)con.getRecord();
    }


    public void save(){

        update theCase;

    }
}

Adding in all necessary checks for null, validation, etc.

the VF Page would then become:

<apex:page standardController="Service_Case__c" extensions="myPageController">
    <apex:form id="theForm">
  <apex:pageBlock title="Service Case Summary">

        <apex:pageBlockSection title="Service Case Stuff"  columns="2">
              <apex:outputField value="{!Service_Case__c.Name}"/>
              <apex:outputField value="{!Service_Case__c.LGFProduct__c}"/>
        </apex:pageBlockSection>

            <apex:pageBlockSection title="Payment" columns="2" rendered="{!if(Service_Case__c.Out_of_Warranty__c, true, false)}">
              <apex:outputField value="{!Service_Case__c.Payment__c}"/>
                <apex:inlineEditSupport disabled="false"/>
              <apex:outputField value="{!Service_Case__c.Received_Payment__c }"/>
                <apex:inlineEditSupport disabled="false"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" rerender="theForm"/>
            </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

This should work but I never use inlineEditSupport because I hate that you have to click out of a field or it will not be saved when you click save. Easier to just use regular input fields and render them as input all the time...or roll your own as needed

Second, without Vf the only way to show or hide fields based on conditions is to use recordTypes and page layouts based on those recordTypes. You will have to weigh the cost of maintaining that with the simplicity of the VF page.

| improve this answer | |
  • There are no problems in the developer console for me but when I preview it, the error "Invalid conversion from runtime type Service_Case__c to Case" pops up. – user1470901 Aug 17 '16 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.