You need to sign in to do that
Don't have an account?
Frank Carter
visualforce checkbox search page wrapper class
Hello,
I Created a vf page with two date input fields:
https://developer.salesforce.com/page/Wrapper_Class
and I tried to modify my code but it does not work and I definitely did something wrong. I want to load records when I click Search button:
vf:
controller:
Can Someone help me?
Thanks
I Created a vf page with two date input fields:
<apex:page controller="searchBDController" docType="html-5.0" id="pg"> <apex:form > <apex:pageBlock title="Billing Details Search Page" > <br/> <br/> <apex:actionRegion > <center> <apex:outputLabel value="Start Date"/> <apex:input value="{!StartDate}" type="date" /><br/> <apex:outputLabel value="End Date "/> <apex:input value="{!EndDate}" type="date" /> </center> </apex:actionRegion> <br/> <div align="center" draggable="false" > <apex:commandButton value="Search" action="{!loadData}" style="text-align:left;" /> <apex:commandButton value="Moves to next month" style="text-align:left;" onclick="if(!confirm('If you click ok all the billing details you are viewing will be paid for next month. Are you sure? ')) return false;" action="{!myAction}" /> </div> </apex:pageBlock> <apex:pageBlock id="pgblk"> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column value="{!b.Name}"/> <apex:column value="{!b.SF_Opportunity_Id__c}"/> <apex:column value="{!b.Billing_Type__c}"/> <apex:column value="{!b.Billing_Period__c}"/> <apex:column value="{!b.Monthly_Forecast__c}"/> <apex:column value="{!b.End_of_Billing__c}"/> <apex:column value="{!b.Amount__c}"/> <apex:column value="{!b.Billing_Status__c}"/> <apex:column > <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">EDIT</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>Controller
public class searchBDController { public Date StartDate {get;set;} public Date EndDate {get;set;} private Boolean changed {get;set;} public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Monthly_Forecast__c ])); } return setCon; } set; } public List<Billing_Detail__c> listBD {get;set;} public String SelectedBdId {get;set;} public void loadData() { listBD = [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Monthly_Forecast__c ]; } //to move monthly forecast public PageReference myAction(){ MoveBD1.Move1(); PageReference pageRef = ApexPages.currentPage(); pageRef.setRedirect(true); return pageRef; } }This page works perfectly but now I have to add checkbox for every record. I read this on wrapper class
https://developer.salesforce.com/page/Wrapper_Class
and I tried to modify my code but it does not work and I definitely did something wrong. I want to load records when I click Search button:
vf:
<apex:page controller="wrapperClassController" docType="html-5.0" id="pg"> <apex:form > <apex:pageBlock title="Billing Details Search Page" > <br/> <br/> <apex:actionRegion > <center> <apex:outputLabel value="Start Date"/> <apex:input value="{!StartDate}" type="date" /><br/> <apex:outputLabel value="End Date "/> <apex:input value="{!EndDate}" type="date" /> </center> </apex:actionRegion> <br/> <div align="center" draggable="false" > <apex:commandButton value="Search" action="{!getBilling}" style="text-align:left;" /> <apex:commandButton value="Moves to next month" style="text-align:left;" onclick="if(!confirm('If you click ok all the billing details you are viewing will be paid for next month. Are you sure? ')) return false;" action="{}" /> </div> </apex:pageBlock> <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/> </apex:pageBlockButtons> <!-- In our table we are displaying the cContact records --> <apex:pageBlockTable value="Billing" var="b" id="table"> <apex:column > <!-- This is our selected Boolean property in our wrapper class --> <apex:inputCheckbox value="{!b.selected}"/> </apex:column> <!-- This is how we access the contact values within our cContact container/wrapper --> <apex:column value="{!b.bil.Name}" /> <apex:column value="{!b.bil.Billing_Status__c}" /> <apex:column value="{!b.bil.Amount__c}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
controller:
public class wrapperClassController { public List<cBilling> BDList {get; set;} public Date StartDate {get;set;} public Date EndDate {get;set;} public List<cBilling> getBilling() { if(BDList == null) { BDList = new List<cBilling>(); for(Billing_Detail__c b: [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Monthly_Forecast__c ]) { // BDList.add(new cBilling(b)); } } return BDList; } public PageReference processSelected() { List<Billing_Detail__c> selectedBilling = new List<Billing_Detail__c>(); for(cBilling cBil: getBilling()) { if(cBil.selected == true) { selectedBilling.add(cBil.bil); } } System.debug('These are the selected Contacts...'); for(Billing_Detail__c bil: selectedBilling) { system.debug(bil); } BDList=null; return null; } public class cBilling { public Billing_Detail__c bil {get; set;} public Boolean selected {get; set;} public cBilling(Billing_Detail__c b) { bil = b; selected = false; } } }
Can Someone help me?
Thanks
Greetings to you!
Please try below code:
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please try below code:
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
If I make a research with the two input date fields and then enter in a record with Last column EDIT when I go back I lost the result records searched. There is a way to obtain last search? every time I go back the search is reset and I must do again the same research. If is it to difficult is it possible to save on controller the values of the date inserted by user in the two date fields input variables? So when I go back I have only to click the search button without setting the 2 dates again.
Thanks again
I’m glad I was able to help!
You can use target="_blank" attribute in outputLink. It will open the edit page in a new tab.Regards,
Khan Anas