function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Waqas AliWaqas Ali 

Show Contracts in VF and change status in VF through Dropdown menu

I have button in opportunity page , When that button is pressed, I want to show my pending contracts in Visual force page and want o Expire or Laspe through VF page. Here is my class
public class myclass {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    
    
    public List<WrapperSObject> records {get; set;}
    public Contract con {get; set;}
    
    public myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
  
 records = new List<WrapperSObject>();
 for (Contract c : [select Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Pending'])
 {
 records.add(new WrapperSObject(c));
 records.add(new WrapperSObject(getOptions(), '--None--'));
}

             return null;
          
}

 

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

     }
     public WrapperSObject(Contract c) {
     con=c;
     }
     
     
  }

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

}

Here is my VF page.
<apex:page standardController="Opportunity"
 extensions="myclass"
 action="{!autoRun}">
  
  <apex:form >

<apex:pageBlock title="My Pending 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 Name</apex:facet> 
                <apex:outputText value="{!wrapper.con.Status}"/> 
            </apex:column>
            
            <apex:column > 
                <apex:facet name="header">Change Status</apex:facet> 
                <apex:selectList value="{!wrapper.selectedValue}" size="1" >
                            <apex:selectOptions value="{!wrapper.options}" />
                        </apex:selectList>
            </apex:column>
                       
        </apex:pageBlockTable>
        
    </apex:pageBlock> 
    </apex:form>
    
   
  
 </apex:page>

Why this small blank Dropdown menu is showing ? 
How to fix this ?
Here is out put
Now how to change the status of these contracts ? I mean how to return the value "Expired or Lapse" and update crosponding Contract ? 

Guys ay help ?

Vivek DeshmaneVivek Deshmane
Hi ,
Try below code and  let if know if it works,

 
public class myclass {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    
    
    public List<WrapperSObject> records {get; set;}
    public Contract con {get; set;}
    
    public myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
  
 records = new List<WrapperSObject>();
 for (Contract c : [select Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Pending'])
 {
 records.add(new WrapperSObject(c));
 records.add(new WrapperSObject(getOptions(), '--None--'));
}

             return null;
          
}

 

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

     }
     public WrapperSObject(Contract c) {
     con=c;
     }
     
     
  }

public List < SelectOption > getOptions() {
List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Expired','Expired'));
        options.add(new SelectOption('LAPSE','Lapse'));
        options.add(new SelectOption('--None--','--None--'));
        // options.add(new SelectOption('--None--',null)); //uncomment this still u will see small boxes and comment above line.
        return options;
    }

}

Best Regards,
-Vivek
 
Waqas AliWaqas Ali
I does not work Vivek.
Waqas AliWaqas Ali
I does not work Vivek.
Vivek DeshmaneVivek Deshmane
Hi,
Try below code , it should work and let me know.
 
public class myclass {
 
    
    String theId = ApexPages.currentPage().getParameters().get('id');
    
    
    public List<WrapperSObject> records {get; set;}
    public Contract con {get; set;}
    
    public myclass(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    public PageReference autoRun() {
  
 records = new List<WrapperSObject>();
 for (Contract c : [select Name, AccountId, StartDate, Status, ContractNumber from Contract where Status='Pending'])
 {
 records.add(new WrapperSObject(c));
 records.add(new WrapperSObject(getOptions(), null));
}

             return null;
          
}

 

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

     }
     public WrapperSObject(Contract c) {
     con=c;
     }
     
     
  }

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

}

Best Regards,
-Vivek
 
Waqas AliWaqas Ali
Here is the error Vivek

Argument 2 cannot be null