• Lorenz Cortez
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hello Everyone,

I have this VF page that can add new rows of fields and delete a row of fields
User-added image

My problem is when I delete the first record or the top most record and then delete the second record it deletes the last row of records. After I deleted the first record it deletes the wrong rows of fields and then when I delete the first record then click the 'Add Skill' button it displays the wrong information in the row. Please Help me out. Thank you very much. My code is down below.

My VF page:

<apex:page standardController="Employee_Skills__c" extensions="AddContacts1" sidebar="false">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <apex:form >
    <apex:pageBlock title="Skill" id="pb">
      <apex:pageMessages />      
      <apex:variable var="rowNumber" value="{!0}"/>
        <apex:pageBlockTable id="thetable" title="Employee_Skills__c" var="empski" value="{!empskilist}">
          <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext">
            <apex:outputText value="{0}" style="text-align:center;">
              <apex:param value="{!rowNumber+1}" />
            </apex:outputText>
          </apex:column>
          <apex:column headerValue="Skill Name" >
            <apex:inputField value="{!empski.Skill_ID__c}"/>
          </apex:column>
          <apex:column headerValue="Proficiency" >
            <apex:inputField value="{!empski.Proficiency__c}"/>
          </apex:column>
          <apex:column headerValue="Skill Type" >
            <apex:inputField value="{!empski.Skill_Type__c}"/>
          </apex:column>
          <apex:column headerValue="Years of Expirience" >
            <apex:inputField value="{!empski.Year_of_Experience__c }"/>
          </apex:column>
          <apex:column headerValue="Action" >
            <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb" immediate="true">
              <apex:param name="rowIndex" value="{!rowNumber}"/>
            </apex:commandButton>
            <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
          </apex:column>
        </apex:pageBlockTable>
           <div align="center" style="margin-top:10px;">  
              <apex:commandButton action="{!addRow}" value="Add Skill" reRender="pb" immediate="true" />   
           </div>
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}" />
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>           
    </apex:pageBlock>
  </apex:form>
</apex:page>


My Controller:

 

public class AddContacts1 {
        public Employee_Skills__c empskill;
        public Employee_Skills__c del;
        public List < Employee_Skills__c > addEmpSkiList {get;set;}
        public List < Employee_Skills__c > delEmpSkiList {get;set;}
        public List < Employee_Skills__c > empskilist{get;set;}
        public Integer totalCount {get;set;}
        public Integer rowIndex {get;set;}
        public List < Employee_Skills__c > delEmpSki {get;set;}

        public AddContacts1(ApexPages.StandardController controller) {
                empskill= (Employee_Skills__c) controller.getRecord();
                empskilist= [SELECT Id,Skill_ID__r.Name,Employee_ID__c,Name,Proficiency__c,Skill_Type__c,Year_of_Experience__c FROM Employee_Skills__c WHERE Employee_ID__c =: empskill.Employee_ID__c];
                totalCount = empskilist.size();
                delEmpSkiList = new List < Employee_Skills__c > ();
                delEmpSki = new List < Employee_Skills__c > ();
        }

        public void addRow() {
                addEmpSkiList = new List < Employee_Skills__c > ();
                empskilist.add(new Employee_Skills__c (Id = empskill.Id,Employee_ID__c = empskill.Employee_ID__c));
        }

        public PageReference save() {
                upsert empskilist;
                delete delEmpSkiList ;
                
              return null;
        }
        public void deleteRow() {
                rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
                del = empskilist.remove(rowIndex);
                
               // if(del.Id != NULL)
               // {
                    delEmpSkiList.add(del);
              //  }
                  
        }
}

Thank you very much.
Hello Everyone,

I should like to convert my Custom Controller to a Standard Controller with an extention so that I can refer my Visualforce Page to a related list button.Please help me out Thank you very much. My code is down below.

VF Page:
 
<apex:page controller="ManageListController" tabstyle="Employee_Skills__c">
 <apex:form id="emp_form">
   <apex:pageBlock title="Create Employee Skill">
      <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
        
         <apex:column headerValue="Ident">
            <apex:outputText value="{!wrapper.ident}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:inputField value="{!wrapper.empski.Skill_ID__c}"/> 
            <apex:actionSupport event="onchange" rerender="pageBlock" status="channelStatus"/>
         </apex:column>
          <apex:column headerValue="Proficiency">
            <apex:inputField value="{!wrapper.empski.Proficiency__c}"/> 
         </apex:column>
         <apex:column headerValue="Skill Type">
            <apex:inputField value="{!wrapper.empski.Skill_Type__c}"/> 
         </apex:column>
         <apex:column headerValue="Years of Experience">
            <apex:inputField value="{!wrapper.empski.Year_of_Experience__c}"/>
         </apex:column>
       
         <apex:column headerValue="Action">
            <apex:commandButton value="Delete" style="Button" action="{!delWrapper}" reRender="wtable" immediate="true">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> 
            </apex:commandButton>
         </apex:column>
         
      </apex:pageBlockTable>
      
       <apex:commandButton value="Add Row" style="Button" action="{!addRows}" reRender="wtable" immediate="true" >
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/> 
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
      
   </apex:pageBlock>
 </apex:form>
</apex:page>


My Custom Controller(That I would like to convert to a extension):

public class ManageListController {
 
     public List<EmpSkillWrapper> wrappers {get; set;}
     public static Integer toDelIdent {get; set;}
     public static Integer addCount {get; set;}
     private Integer nextIdent=0;
     
      public PageReference pageRef;
      public Employee_Skills__c getEmp;
     public Employee_Skills__c empi {set; get;}
     
     
     public ManageListController(ApexPages.StandardController controller) {
            
             this.getEmp = (Employee_Skills__c) controller.getRecord();
             this.empi = new Employee_Skills__c();
             wrappers = new List<EmpSkillWrapper>();
    }
     
     
     public ManageListController()
     {
          wrappers=new List<EmpSkillWrapper>();
          for (Integer idx=0; idx<1; idx++)
          {
           wrappers.add(new EmpSkillWrapper(nextIdent++));
          }
     }
      
   
     public class EmpSkillWrapper{
          public Employee_Skills__c empski {get;set;}
          public Integer ident {get;set;}
           
          public EmpSkillWrapper(Integer inIdent){
               ident=inIdent;
              empski=new Employee_Skills__c();
          }
     }
    
    public PageReference save(){
          
          List<Employee_Skills__c> eskills=new List<Employee_Skills__c>();
          for (EmpSkillWrapper wrap : wrappers){
               eskills.add(wrap.empski);
          }
           
          insert eskills;
           
          return new PageReference('/' + Schema.getGlobalDescribe().get('Employee_Skills__c').getDescribe().getKeyPrefix() + '/o');
          return null;
        // return new PageReference('/' + empski.Employee_ID__c);
         // return null;
    
     }
    
    public void addRows(){
          
          for (Integer idx=0; idx<addCount; idx++){
           wrappers.add(new EmpSkillWrapper(nextIdent++));
          }
         
     }
    
      public void delWrapper(){
          
          Integer toDelPos=-1;
          for (Integer idx=0; idx<wrappers.size(); idx++){
               if (wrappers[idx].ident==toDelIdent){
                    toDelPos=idx;
               }
          }
       
            if (-1!=toDelPos)
              {
                  if(wrappers.size() !=1){
                       wrappers.remove(toDelPos);
                       
                       }
              }
     }
      
      

     
}

Thank you in advance.

Hello Everyone,

I have this VF page that can add new rows of fields and delete a row of fields
User-added image

My problem is when I delete the first record or the top most record and then delete the second record it deletes the last row of records. After I deleted the first record it deletes the wrong rows of fields and then when I delete the first record then click the 'Add Skill' button it displays the wrong information in the row. Please Help me out. Thank you very much. My code is down below.

My VF page:

<apex:page standardController="Employee_Skills__c" extensions="AddContacts1" sidebar="false">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <apex:form >
    <apex:pageBlock title="Skill" id="pb">
      <apex:pageMessages />      
      <apex:variable var="rowNumber" value="{!0}"/>
        <apex:pageBlockTable id="thetable" title="Employee_Skills__c" var="empski" value="{!empskilist}">
          <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext">
            <apex:outputText value="{0}" style="text-align:center;">
              <apex:param value="{!rowNumber+1}" />
            </apex:outputText>
          </apex:column>
          <apex:column headerValue="Skill Name" >
            <apex:inputField value="{!empski.Skill_ID__c}"/>
          </apex:column>
          <apex:column headerValue="Proficiency" >
            <apex:inputField value="{!empski.Proficiency__c}"/>
          </apex:column>
          <apex:column headerValue="Skill Type" >
            <apex:inputField value="{!empski.Skill_Type__c}"/>
          </apex:column>
          <apex:column headerValue="Years of Expirience" >
            <apex:inputField value="{!empski.Year_of_Experience__c }"/>
          </apex:column>
          <apex:column headerValue="Action" >
            <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb" immediate="true">
              <apex:param name="rowIndex" value="{!rowNumber}"/>
            </apex:commandButton>
            <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
          </apex:column>
        </apex:pageBlockTable>
           <div align="center" style="margin-top:10px;">  
              <apex:commandButton action="{!addRow}" value="Add Skill" reRender="pb" immediate="true" />   
           </div>
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}" />
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>           
    </apex:pageBlock>
  </apex:form>
</apex:page>


My Controller:

 

public class AddContacts1 {
        public Employee_Skills__c empskill;
        public Employee_Skills__c del;
        public List < Employee_Skills__c > addEmpSkiList {get;set;}
        public List < Employee_Skills__c > delEmpSkiList {get;set;}
        public List < Employee_Skills__c > empskilist{get;set;}
        public Integer totalCount {get;set;}
        public Integer rowIndex {get;set;}
        public List < Employee_Skills__c > delEmpSki {get;set;}

        public AddContacts1(ApexPages.StandardController controller) {
                empskill= (Employee_Skills__c) controller.getRecord();
                empskilist= [SELECT Id,Skill_ID__r.Name,Employee_ID__c,Name,Proficiency__c,Skill_Type__c,Year_of_Experience__c FROM Employee_Skills__c WHERE Employee_ID__c =: empskill.Employee_ID__c];
                totalCount = empskilist.size();
                delEmpSkiList = new List < Employee_Skills__c > ();
                delEmpSki = new List < Employee_Skills__c > ();
        }

        public void addRow() {
                addEmpSkiList = new List < Employee_Skills__c > ();
                empskilist.add(new Employee_Skills__c (Id = empskill.Id,Employee_ID__c = empskill.Employee_ID__c));
        }

        public PageReference save() {
                upsert empskilist;
                delete delEmpSkiList ;
                
              return null;
        }
        public void deleteRow() {
                rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
                del = empskilist.remove(rowIndex);
                
               // if(del.Id != NULL)
               // {
                    delEmpSkiList.add(del);
              //  }
                  
        }
}

Thank you very much.