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.

  • Ca u provide What are the errors you r getting – Sunny Dec 24 '13 at 6:41
  • Sorry I not getting any error the fields show an editable but I need the custom fields are read only – Ramesh S Dec 24 '13 at 6:50
  • U mean after clicking save button data is saving correctly and u need to make the fields as readonly Right? – Sunny Dec 24 '13 at 6:53
  • Yes I need the same – Ramesh S Dec 24 '13 at 6:59
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>

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.