0

i have a scenario, i want to increment a value in wrapper class let's take testWrapper class is there , having a Integer variable called incrementX For ex 5 records are there , 1st Recorde --> incrementX value should be 0; 2 nd Record --> incrementX value should be 1; 3 rd Record --> incrementX value should be 2; 4 th Record --> incrementX value should be 3; 5 th Record --> incrementX value should be 4

public class mainClass{
  public mainClass(){

     for(pse__project_task__c prjTask:lstProjectTask){
        lstwrapperList.add(new validateWrapper(prjTask,subTaskDurationAPJ,subTaskDurationEMEA,subTaskDurationAmericas,mapProjectTaskRegion,R6orR7Tasks,validSkillCheck,mapForState));
        projName=prjTask.pse__project__r.name;

     }
  }

}

public class validateWrapper{
        public pse__project_task__c projectTask{get;set;}
        public Boolean isValidSkill{get;set;}
        public Double  deliveryHoursLimit{get;set;}
        public string skillsTooltip{get;set;}
        public List<pse__project_task__c> projectTaskId=new List<pse__project_task__c>();
        public Boolean isValidstate{get;set;}
        public Integer incrementForList{get;set;}
              //incrementForList=0;

        public validateWrapper(pse__project_task__c task,Double APJ, Double EMEA, Double Americas,map<id,string> mapProjectTaskRegion,map<id,string> R6orR7Tasks,map<id,boolean> validSkillCheck,Map<pse__project_Task__c,boolean> mapValidState){
            isValidSkill=false;
            deliveryHoursLimit=0;
            projectTask=task;
             //incrementForList=0;

            system.debug('incrementForList-->'+task.name+'--'+incrementForList);
            incrementForList++;
            //Check is the task is R6 or R7 and task will have valid Skills
            if(R6orR7Tasks.get(task.id)=='R6'){
                skillsTooltip='At least one skill is mandatory';
                if(validSkillCheck.get(task.id)==true){
                    isValidSkill=true;
                }
            }
            else if(R6orR7Tasks.get(task.id)=='R7'){
                skillsTooltip='At least one service skill and one Support skill is Mandatory';
                if(validSkillCheck.get(task.id)==true){
                    isValidSkill=true;
                }
            }
              //state validation
                isValidstate=mapValidState.get(task);


            //Checing the Region and assigning the delivery estimated hours

            if(mapProjectTaskRegion.get(task.id)==System.Label.GSD_Contract_Reference_APJ){
                deliveryHoursLimit=APJ;
            }
            else if(mapProjectTaskRegion.get(task.id)==System.Label.GSD_Contract_Reference_EMEA){
                deliveryHoursLimit=EMEA;
            }
            else if(mapProjectTaskRegion.get(task.id)==System.Label.GSD_Contract_Reference_AMS){
                deliveryHoursLimit=Americas;
            }


        }
    }
6
  • If you're in a loop when you instantiate your wrappers it should be really easy. But if you don't post code, we can't help you. Mar 30 '17 at 7:15
  • Code Posted ....... Mar 30 '17 at 7:18
  • Are you displaying wrapper list on VF page using pageblocktable? Mar 30 '17 at 7:22
  • 1
    You should post the code where you are creating list?
    – Ashwani
    Mar 30 '17 at 7:22
  • yes rohit , i am using wrapper list in VF page Mar 30 '17 at 7:24
1

You will have to add one more parameter to retain the incremented value. Approach would be as follow:-

     Integer countValue = 1 // or any predefined value;
     for(pse__project_task__c prjTask:lstProjectTask){
        lstwrapperList.add(new validateWrapper(prjTask,subTaskDurationAPJ,subTaskDurationEMEA,subTaskDurationAmericas,mapProjectTaskRegion,R6orR7Tasks,validSkillCheck,mapForState,countValue));
        projName=prjTask.pse__project__r.name;
        countValue++; // Or any other logic
     }

Wrapper class:-

// Added countValue parameter which can be assigned    
public validateWrapper(pse__project_task__c task,Double APJ, Double EMEA, Double Americas,map<id,string> mapProjectTaskRegion,map<id,string> R6orR7Tasks,map<id,boolean> validSkillCheck,Map<pse__project_Task__c,boolean> mapValidState, Integer countValue){
        isValidSkill=false;
        deliveryHoursLimit=0;
        incrementForList = countValue; // new logic
        // ....


    }
1

@Ashwani has suggested one approach, but there is one more way to achieve this by using apex:variable.

  1. Create a apex:variable and use it in a pageblocktable or apex:repeat.

  2. Increment the value of apex:variable inside it and display it in apex:outputText.

Refer below example:

<apex:variable value="{!0}" var="rowNum"/>

<apex:pageblockTable value="{!lstwrapperList}" var="wrapperItem">

    <apex:column >
        <apex:outputText >
            {!rowNum}
            <apex:variable value="{!rowNum+ 1}" var="rowNum" />
        </apex:outputText>
    </apex:column>

    <apex:column >
        <apex:commandLink status="Delete" action="{!selectedRecord }">
            <apex:param name="index" value="{!rowNum}" assignTo="index"/>
        </apex:commandLink>
    </apex:column>

</apex:pageblockTable>

If you want to take any action on a particular record in a page block table then this can also be done by creating a commandButton and send rowNum as a parameter to apexMethod() and get that record from lstwrapperList

Example:

public Integer index{get;set;}

public void selectedRecord (){
   validateWrapper vwrapper = lstwrapperList.get(index);
}

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.