+ Start a Discussion
Varun AnnadataVarun Annadata 

Help with functionality of button

Apex Class:
public with sharing class SkipMilestone{
    public List<Program_Member_Stage_MVN__c>Pms{get;set;}
    public List<ProgramWrapper>PmsWrapper{get;set;}
    public Program_Member_MVN__c Pm;
    public SkipMilestone(ApexPages.StandardController controller) {    
    Pm = (Program_Member_MVN__c)controller.getRecord();
        List<Program_Member_Stage_MVN__c>Pms =[select id,Name,Program_Stage_MVN__c,Status_MVN__c,Program_Stage_Name_MVN__c from Program_Member_Stage_MVN__c where Program_Member_MVN__c=:Pm.id and Status_MVN__c='Not Started'];
            if(Pms != null && Pms .size() > 0){
               displayStages(Pms);
    system.debug('Pms:'+Pms);
    }
    }
    
    public void displayStages(List<Program_Member_Stage_MVN__c>Pms)
    {
   PmsWrapper=new  List<ProgramWrapper>();
     for(Program_Member_Stage_MVN__c PmObj : Pms){
       PmsWrapper.add(new ProgramWrapper(PmObj));
    }
    }
    public void complete(){
    PmsWrapper=new  List<ProgramWrapper>();
        for(ProgramWrapper ow : PmsWrapper){
        if(ow.isChecked){
              ow.PmStatus='Started';
             // PmsWrapper.add(new ProgramWrapper(ow));
            }  
          //  update PmsWrapper;
        }
        }
       
     public class ProgramWrapper{ 
     public string PmId{get;set;}
      public String PmName{get;set;}
        public String Pmstage{get;set;}
        public Boolean isChecked {get;set;}
        public String PmStatus{get;set;}
        
        
         public ProgramWrapper(Program_Member_Stage_MVN__c PmObj){
         this.PmId=PmObj.id;
          this.PmName= PmObj.Name;
            this.Pmstage= PmObj.Program_Stage_Name_MVN__c;
            this.isChecked = false;
            this.PmStatus= PmObj.Status_MVN__c ;
    }
    }
    }

Visual force Page:
<apex:page standardcontroller="Program_Member_MVN__c" extensions="SkipMilestone" >
  
    <apex:form >
        <apex:pageBlock >
            <apex:pageblocktable value="{!PmsWrapper}" var="Pm">
                <apex:column ><apex:inputCheckbox value="{!Pm.isChecked}" /></apex:column>
                <apex:column headervalue="Name" value="{!Pm.PmName}"/>
                <apex:column headervalue="Stage Name" value="{!Pm.Pmstage}"/>
                <apex:column headervalue="Status" value="{!Pm.PmStatus}"/>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Complete" onclick="complete" />  
                </apex:column>
            </apex:pageblocktable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


The functionality i want is when i click the button which is displayed at the end of records it should update the status field of that particular record to completed.
How should i write the logic in: 
public void complete(){
    PmsWrapper=new  List<ProgramWrapper>();
        for(ProgramWrapper ow : PmsWrapper){
        if(ow.isChecked){
              ow.PmStatus='Started';
             // PmsWrapper.add(new ProgramWrapper(ow));
            }  
          //  update PmsWrapper;
        }
        }
To update the status field of that record to "completed"?
Visual force page will look like:
User-added image
LBKLBK
hi Varun,

You can pass a parameter to the command button to achieve this.

Your Commandbutton code will look like this.
<apex:commandButton value="Complete" onclick="complete">
	<apex:param name="PmsId" value="{!Pm.id}" assignTo="{!paramValue}"/>
</apex:commandButton>
And the APEX method will be like this.
public String paramValue {get;set;}
public PageReference complete(){
	ProgramWrapper objProgramWrapper = ProgramWrapper();
	objProgramWrapper.Id = this.paramValue;
	objProgramWrapper.PmStatus='Completed';
	update objProgramWrapper;
	
	PageReference pageRef = new PageReference("/apex/YOUR_VF_PAGE_NAME");
	return pageRef;
}
As you can see, I have defined a public property named paramValue before the method. You can move it to the top of your class.

And, replace YOUR_VF_PAGE_NAME with your actual Visualforce page name, so that the page refresh will happen automatically after saving.

Let me know how it goes.