0

I have one VF page that contains custom fields: VF Page : DEMO

<apex:page standardController="Order__c" extensions="MyOrderPadController" >       
     <apex:detail />
        <apex:form >    
        <apex:pageBlock >      
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            </apex:pageBlockButtons>                       
            <apex:pageBlockSection columns="2" title="Order Pad">
            <apex:inputField value="{!Order__c.Order_Description__c}"  />
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:inputField value="{!Order__c.Conformation__c}"  />                                          
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form> 

</apex:page>

Controller :MyOrderPadController

public class MyOrderPadController {
    public Order__c order{ get; private set;} 

    public MyOrderPadController (){}

public MyOrderPadController(ApexPages.StandardController sc) {

    order = (Order__c)sc.getRecord();
    order.Account__c = ApexPages.currentPage().getParameters().get('aid');  
}
public PageReference edit() 
     { 
           return null;        
     }
 public PageReference reset()
 {
      PageReference newpage = new PageReference(System.currentPageReference().getURL());

      newpage.setRedirect(true);
      return newpage;
}
 public PageReference save() 
 {
      TRY
      {              
           order.Name = 'Demo ';                                      
            IF(order.Conformation__c == TRUE){                          
                INSERT order; 
                PageReference newpage = new                PageReference(System.currentPageReference().getURL());
                newpage.setRedirect(true);
                return newpage;     
                }


                }   

      catch(System.DMLException e) 
      {
        ApexPages.addMessages(e);
        SYSTEM.DEBUG('ERROR ORDER PAD CONTROLLER :'+e);
        return null;
      }
    //  After Save, navigate to the default view page:
    //return (new ApexPages.StandardController(order)).view();
    return null;        
 }   
}

My question is after click the save button all fields in the VF page not editable (read only),future edit possible,User where ever click the conformation checked then at the time only record is insert in the "Order__c",user unchecked conformation then click the save button save the VF page read only.Please some one help me.

4
  • Ca u provide What are the errors you r getting
    – Sunny
    Commented Dec 24, 2013 at 6:41
  • Sorry I not getting any error the fields show an editable but I need the custom fields are read only Commented Dec 24, 2013 at 6:50
  • U mean after clicking save button data is saving correctly and u need to make the fields as readonly Right?
    – Sunny
    Commented Dec 24, 2013 at 6:53
  • Yes I need the same Commented Dec 24, 2013 at 6:59

1 Answer 1

1
In that case use the below code

public class MyOrderPadController {
    public Order__c order{ get; private set;} 
    public string statusM{get;set;}

    public MyOrderPadController (){}

public MyOrderPadController(ApexPages.StandardController sc) {

    order = (Order__c)sc.getRecord();
    order.Account__c = ApexPages.currentPage().getParameters().get('aid'); 
    statusM = false; 
}
public PageReference edit() 
     { 
           return null;        
     }
 public PageReference reset()
 {
      PageReference newpage = new PageReference(System.currentPageReference().getURL());

      newpage.setRedirect(true);
      return newpage;
}
 public PageReference save() 
 {
      TRY
      {              
           order.Name = 'Demo ';                                      
            IF(order.Conformation__c == TRUE){                          
                INSERT order; 
                statusM = true;
                PageReference newpage = new                PageReference(System.currentPageReference().getURL());
                newpage.setRedirect(true);
                return newpage;     
                }


                }   

      catch(System.DMLException e) 
      {
        ApexPages.addMessages(e);
        SYSTEM.DEBUG('ERROR ORDER PAD CONTROLLER :'+e);
        return null;
      }
    //  After Save, navigate to the default view page:
    //return (new ApexPages.StandardController(order)).view();
    return null;        
 }   
}



Page:

<apex:page standardController="Order__c" extensions="MyOrderPadController" >       
     <apex:detail />
        <apex:form >    
        <apex:pageBlock >      
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            </apex:pageBlockButtons>                       
            <apex:pageBlockSection columns="2" title="Order Pad">
            <apex:inputField value="{!Order__c.Order_Description__c}" disabled="{!if(statusM==true,true,false)}"/>
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  disabled="{!if(statusM==true,true,false)}"/>
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  disabled="{!if(statusM==true,true,false)}"/>
                     <apex:inputField value="{!Order__c.Conformation__c}" disabled="{!if(statusM==true,true,false)}" />                                          
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form> 

</apex:page>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .