• Manish Soni 7
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I want to show all active contracts in VF page and want to change their status either "Expired" or "Lapse" in VF. 
Here is my VF page
<apex:page standardController="Opportunity"
 extensions="Opp2Order"
 action="{!autoRun}">
  
  <apex:form >

<apex:pageBlock title="My Active Contracts" > 
        <apex:pageBlockTable value="{!records}"  var="wrapper"> 
             <apex:column > 
                <apex:facet name="header">Contract Number</apex:facet> 
                <apex:outputText value="{!wrapper.con.ContractNumber}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Contract ID</apex:facet> 
                <apex:outputText value="{!wrapper.con.id}"/> 
            </apex:column> 
            
            <apex:column > 
                <apex:facet name="header">Change Status</apex:facet> 
                <apex:selectList value="{!wrapper.selectedValue}" size="1" onchange="changeStatus()" >
                            <apex:selectOptions value="{!wrapper.options}" />  
                        </apex:selectList>
                        
           </apex:column> 
              </apex:pageBlockTable>    
         </apex:pageBlock> 
  <apex:commandButton action="{!back}" value="Save!" />
  
    </apex:form>
  
  
</apex:page>
Here is my class
 
public class Opp2Order {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    
    
    public List<WrapperSObject> records {get; set;}
    public Contract con {get; set;}
    public String selectedValue {get; set;}
 
   public Opp2Order(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
  records = new List<WrapperSObject>();
 for (Contract c : [select id, Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Activated'])
 {
 records.add(new WrapperSObject(c, getOptions(), 'Activated'));
 }

             return null;         
}

 public PageReference back() {
  // How to here update the status of all contracts 
  }
 
 public void changeStatus()
 {
    // in back() method or in this method ? I am confused
 }

public class WrapperSObject {
public Contract con {get; set;}
 public List < SelectOption > options {get; set;}
        public String selectedValue {get; set;}
  
     
    public WrapperSObject( Contract c,List < SelectOption > options, String selectedValue) {
    con=c;
     this.options = options;
     this.selectedValue = selectedValue;
     }
  
  }

public List < SelectOption > getOptions() {
List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Activated','Activated'));
        options.add(new SelectOption('Expired','Expired'));
        options.add(new SelectOption('LAPSE','Lapse'));
        return options;
    }
}

I want to update the status of all contracts according to selection in VF page. How to get selected value from VF pick list and how to use in Apex class. 

I am confused wether i can pick selected value and update contract status in Onchange() method or in back() method i should update the status of all contracts. How i am supposed to do that. I am stucked badly. Guy's help.  
 

I want to show all active contracts in VF page and want to change their status either "Expired" or "Lapse" in VF. 
Here is my VF page
<apex:page standardController="Opportunity"
 extensions="Opp2Order"
 action="{!autoRun}">
  
  <apex:form >

<apex:pageBlock title="My Active Contracts" > 
        <apex:pageBlockTable value="{!records}"  var="wrapper"> 
             <apex:column > 
                <apex:facet name="header">Contract Number</apex:facet> 
                <apex:outputText value="{!wrapper.con.ContractNumber}"/> 
            </apex:column> 
            <apex:column > 
                <apex:facet name="header">Contract ID</apex:facet> 
                <apex:outputText value="{!wrapper.con.id}"/> 
            </apex:column> 
            
            <apex:column > 
                <apex:facet name="header">Change Status</apex:facet> 
                <apex:selectList value="{!wrapper.selectedValue}" size="1" onchange="changeStatus()" >
                            <apex:selectOptions value="{!wrapper.options}" />  
                        </apex:selectList>
                        
           </apex:column> 
              </apex:pageBlockTable>    
         </apex:pageBlock> 
  <apex:commandButton action="{!back}" value="Save!" />
  
    </apex:form>
  
  
</apex:page>
Here is my class
 
public class Opp2Order {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    
    
    public List<WrapperSObject> records {get; set;}
    public Contract con {get; set;}
    public String selectedValue {get; set;}
 
   public Opp2Order(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
  records = new List<WrapperSObject>();
 for (Contract c : [select id, Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Activated'])
 {
 records.add(new WrapperSObject(c, getOptions(), 'Activated'));
 }

             return null;         
}

 public PageReference back() {
  // How to here update the status of all contracts 
  }
 
 public void changeStatus()
 {
    // in back() method or in this method ? I am confused
 }

public class WrapperSObject {
public Contract con {get; set;}
 public List < SelectOption > options {get; set;}
        public String selectedValue {get; set;}
  
     
    public WrapperSObject( Contract c,List < SelectOption > options, String selectedValue) {
    con=c;
     this.options = options;
     this.selectedValue = selectedValue;
     }
  
  }

public List < SelectOption > getOptions() {
List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Activated','Activated'));
        options.add(new SelectOption('Expired','Expired'));
        options.add(new SelectOption('LAPSE','Lapse'));
        return options;
    }
}

I want to update the status of all contracts according to selection in VF page. How to get selected value from VF pick list and how to use in Apex class. 

I am confused wether i can pick selected value and update contract status in Onchange() method or in back() method i should update the status of all contracts. How i am supposed to do that. I am stucked badly. Guy's help.