You need to sign in to do that
Don't have an account?

apex issue
Hello
I am validating my salesforce concepts.
when vf page loads it will generate 4 records where I can enter values . when I click Getrows button I am able to fetch all data.
now out of 4 records if I select 4 th record for delete then the first record gets deleted not the fourth one.
Please let me know the issue
I am validating my salesforce concepts.
when vf page loads it will generate 4 records where I can enter values . when I click Getrows button I am able to fetch all data.
now out of 4 records if I select 4 th record for delete then the first record gets deleted not the fourth one.
Please let me know the issue
public class Student_Wrapper { public String name {set;get;} public String course {set;get;} public String branch {set;get;} public Decimal fee {set;get;} public Boolean flag {set;get;} } public class StudentLineItems { public Integer rowNo { get; set; } public List<Student_Wrapper> students{get;set;} public List<Student_Wrapper> selected{get;set;} public StudentLineItems() { students=new List<Student_Wrapper>(); addRows(); } public void addRows() { students=new List<Student_Wrapper>(); for(integer i=1;i<=4;i++) { Student_Wrapper sd=new Student_Wrapper(); students.add(sd); } } public void getData() { if (students != NULL) { selected=new List<Student_Wrapper>(); for(Student_Wrapper sw:students) { if(sw.flag == true) selected.add(sw); } } } public void addEle() { Student_Wrapper s=students.get(rowNo); if(rowNo+1<students.size()) students.add(rowNo+1,s); else students.add(s); } public void removeEle() { if (rowNo <=students.size()) students.remove(rowNo); } } <apex:page controller="StudentLineItems"> <apex:form id="frm1"> <apex:inputHidden value="{!rowNo}" id="hid" /> <apex:pageBlock title="student details" id="pb1"> <apex:pageBlockButtons location="top"> <apex:commandButton value="Add Rows" action="{!addRows}"/> <apex:commandButton value="Get Rows" action="{!getData}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!students}" var="stud" id="pgblck1"> <apex:column > <apex:inputCheckbox value="{!stud.flag}"/> </apex:column> <apex:column headerValue="Name"> <apex:inputText value="{!stud.Name}" /> </apex:column> <apex:column headerValue="course"> <apex:inputText value="{!stud.course}" /> </apex:column> <apex:column headerValue="branch"> <apex:inputText value="{!stud.branch}"/> </apex:column> <apex:column headerValue="fee"> <apex:inputText value="{!stud.fee}"/> </apex:column> <apex:column > <apex:commandButton value="Add" id="b1" action="{!addEle}"/> <apex:commandButton value="Del" id="b2" action="{!removeEle}" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Student data"> <apex:pageBlockTable value="{!selected}" var="a"> <apex:column headerValue="Student Name"> <apex:outputText value="{!a.name}" /> </apex:column> <apex:column headerValue="Course"> <apex:outputText value="{!a.course}"/> </apex:column> <apex:column headerValue="Branch"> <apex:outputText value="{!a.branch}"/> </apex:column> <apex:column headerValue="Fee"> <apex:outputText value="{!a.fee}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Its very difficult to read your code and than find out what is wrong.
What is understand is that you are deleting student row based on the rowNo so if you want to delete the right value than please debug the value of rowNo and try to find out the cause for your issue.
If you are still not able to sort it out than please contact me on gmail or skype so that i can provide you help.
Gmail : abhibansal2790@gmail.com
SkypeId : abhishek.bansal2790
Thanks,
Abhishek
I see you are not initializing RowNo anywhere, so any of your calculations that depend on RowNo var will work!. I guess you want to remove a specific row when clicking on the row "delete" button. For that, you could initialize RowNo variable in each line passing it as a parameter in each command button.
Take a look at this great post in which something similar is done: http://bobbuzzard.blogspot.com.es/2011/07/passing-parameters-to-apex-method-from.html
Best regards!