You need to sign in to do that
Don't have an account?
aditya naidu
Can we fetch multiple records using controller class?
I am tring to fetch multiple record and update them, but when ever i try to fetch the second record automatically the page get reefreshed and goes to the first row.
The code is:
visualforce page:
<apex:page controller="binsert">
<apex:form >
<apex:pageBlock title="bulk insert">
<apex:pageBlockButtons >
<apex:commandButton value="add row" action="{!addr}"/>
<apex:commandButton value="save row" action="{!saver}"/>
<apex:commandButton value="fetch" action="{!fetch}"/>
<apex:commandButton value="update" action="{!updat}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable var="bu" value="{!buk}">
<apex:column headerValue="Book Name">
<apex:inputField value="{!bu.name}"/>
</apex:column>
<apex:column headerValue="Book Author">
<apex:inputField value="{!bu.book_author__c}"/>
</apex:column>
<apex:column headerValue="Book Cost">
<apex:inputField value="{!bu.book_cost__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller class:
public class binsert {
public PageReference updat() {
update buk;
return null;
}
public pagereference fetch() {
buk=[select id,name,book_author__c,book_cost__c from book__c where name=:bo.name];
return null;
}
public PageReference saver() {
insert buk;
return page.bulkinsert;
}
public PageReference addr() {
book__c buuk=new book__c();
buk.add(buuk);
return null;
}
book__c bo=new book__c();
public list<book__c> buk{get; set;}
public binsert(){
buk=new list<book__c>();
buk.add(bo);
}
}
can you please help me out to fetch multiple record and update.
Your suggestion is well appreciated.
Thank you!!
The code is:
visualforce page:
<apex:page controller="binsert">
<apex:form >
<apex:pageBlock title="bulk insert">
<apex:pageBlockButtons >
<apex:commandButton value="add row" action="{!addr}"/>
<apex:commandButton value="save row" action="{!saver}"/>
<apex:commandButton value="fetch" action="{!fetch}"/>
<apex:commandButton value="update" action="{!updat}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable var="bu" value="{!buk}">
<apex:column headerValue="Book Name">
<apex:inputField value="{!bu.name}"/>
</apex:column>
<apex:column headerValue="Book Author">
<apex:inputField value="{!bu.book_author__c}"/>
</apex:column>
<apex:column headerValue="Book Cost">
<apex:inputField value="{!bu.book_cost__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller class:
public class binsert {
public PageReference updat() {
update buk;
return null;
}
public pagereference fetch() {
buk=[select id,name,book_author__c,book_cost__c from book__c where name=:bo.name];
return null;
}
public PageReference saver() {
insert buk;
return page.bulkinsert;
}
public PageReference addr() {
book__c buuk=new book__c();
buk.add(buuk);
return null;
}
book__c bo=new book__c();
public list<book__c> buk{get; set;}
public binsert(){
buk=new list<book__c>();
buk.add(bo);
}
}
can you please help me out to fetch multiple record and update.
Your suggestion is well appreciated.
Thank you!!
Please take the below code:
Class:
Please let me know if this helps.
Regards,
Mahesh
there are multiple records in book__c, and i wanna fetch a particular record from the S-object again when i click at add row there will be empty row fields displayed and i want to mention a particular book name and fetch it again but here in my scenario i am unable to do it, When ever i click add row and try to fetch the details it is automatically refreshing and going to the first row, Kindly advice how can i acheive it.
Thanks for responding to my query, I am facing the same issue.
In first row i am able to fetch the records by mentioning the name.
when i click at add row there will be empty row fields displayed and i want to mention a particular book name and fetch it again but here in my scenario i am unable to do it, When ever i click add row and try to fetch the details it is automatically refreshing and going to the first row, Kindly advice how can i acheive it.
Regards
Aditya Naidu
I treied the code but i am unable to fetch ,multiple records when i click add row and when i click fetch record automatically the page gets refreshed and goes to the first row
I have modified the mahesh code in the fetch method slightly. Replace the fetch method in the mahes code with the below and give a try. I hope this gives you the solution.
let me know with errors, if you face any .
NOTE: MARK THIS ANSWER AS BEST ANSWER IF IT ANSWERS TO YOUR QUESTION.
Regards,
Sai Krishna Tavva.