-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
21Questions
-
48Replies
problem with test class for search page
hi, I'm hoping someone can point me in the right direction.
I have a vf page to search child object related to Opportunity.
In input user have to insert two string Inputtext (owner and id opportunity).
In apex class there is a void method load data:
Apex class:
the test class:
The code coverage is 61% but i don't understand why it's like it doesn't see the content of the inputValue1 and inputValue2.
I'm hoping someone could have a look at my test class and let me know how I should go about passing these parameters.
any help would be appreciated
Thanks
I have a vf page to search child object related to Opportunity.
In input user have to insert two string Inputtext (owner and id opportunity).
In apex class there is a void method load data:
Apex class:
public class SearchWithWrapperSS { public Date StartDate {get;set;} public Date EndDate {get;set;} public String inputValue1 {get;set;} public String inputValue2 {get;set;} public List<WrapperClass> listBD {get;set;} public List<Billing_Detail__c> blst=new List<Billing_Detail__c>(); public void loadData() { if ((! String.isBlank(inputValue1))&&(String.isBlank(inputValue2))){ String Owner; List <User> userList = [Select id, Name from User where Email =: inputValue1]; if(! userList.isEmpty()){ Owner = userList[0].id; List <Billing_Detail__c> billingList = [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Detail__c IN (select id from Opportunity where OwnerId=:Owner)and Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]; listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : billingList ){ listBD.add(new WrapperClass (cr, false)); } } } else if ((! String.isBlank(inputValue1))&&(! String.isBlank(inputValue2))){ String Owner; List <User> userList = [Select id, Name from User where Email =: inputValue1]; if(! userList.isEmpty()){ Owner = userList[0].id; List <Billing_Detail__c> listBilling = [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Detail__c IN (select id from Opportunity where OwnerId=:Owner) and Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and SF_Opportunity_Id__c=:inputValue2 and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]; listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : listBilling){ listBD.add(new WrapperClass (cr, false)); } } } else if (! String.isBlank(inputValue2)){ listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and SF_Opportunity_Id__c=:inputValue2 and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } else{ listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference changeStatus() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); billlingDetail.Billing_Status__c= 'Authorized for Billing'; selectedBD.add(billlingDetail); } } update selectedBD; loadData(); return null; } public PageReference processSelected() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); if (bd.cs.Monthly_Forecast__c.month()==12) { billlingDetail.Monthly_Forecast__c = Date.newinstance( bd.cs.Monthly_Forecast__c.year()+1 , 01 , bd.cs.Monthly_Forecast__c.day() ); billlingDetail.Billing_Competence_Forecast__c = billlingDetail.Monthly_Forecast__c; selectedBD.add(billlingDetail); } else{ billlingDetail.Monthly_Forecast__c = Date.newinstance( bd.cs.Monthly_Forecast__c.year() , bd.cs.Monthly_Forecast__c.month()+1, bd.cs.Monthly_Forecast__c.day() ); billlingDetail.Billing_Competence_Forecast__c = billlingDetail.Monthly_Forecast__c; selectedBD.add(billlingDetail); } } } update selectedBD; loadData(); return null; } //save public PageReference toSave() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; billlingDetail = new Billing_Detail__c(Id=bd.cs.Id,Amount__c=bd.cs.Amount__c, Billing_Type__c=bd.cs.Billing_Type__c,Billing_Competence_Forecast__c=bd.cs.Billing_Competence_Forecast__c, Billing_Period__c=bd.cs.Billing_Period__c, Billing_Status__c=bd.cs.Billing_Status__c, Monthly_Forecast__c=bd.cs.Monthly_Forecast__c,End_of_Billing__c=bd.cs.End_of_Billing__c ); selectedBD.add(billlingDetail); } update selectedBD; loadData(); return null; } public PageReference toDelete() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); selectedBD.add(billlingDetail); } } delete selectedBD; loadData(); return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
the test class:
@isTest private class SearchWithWrapperSSTest { @isTest static void testController() { Test.startTest(); Id RecordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Customer_user').getRecordTypeId();//get only macrostructure RT // create the object in input of the class Account a= new Account(); a.name='Account test t'; //a.RecordTypeId='012w0000000iROM'; a.Branch__c='Italy'; a.Status__c='Customer'; a.BillingCountry='Italy'; a.Public_Administration_Account__c='No'; insert a; Opportunity testOpportunity = new Opportunity( AccountID = a.Id, Name = 'Test Opportunity', StageName = 'Needs Analysis', CloseDate = date.today().addDays(15) ); insert testOpportunity; Billing_Detail__c c= new Billing_Detail__c(); c.Amount__c= 100; c.Billing_Type__c='FEE'; c.Billing_Period__c='monthly'; c.Billing_Status__c='Authorized for Billing'; c.Product_Line__c='Interactive Experience (iX)'; c.Product__c='Chat Delivery'; c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); c.End_of_Billing__c=Date.newInstance(2019, 7, 9); c.Billing_Detail__c=testOpportunity.Id; insert c; User u = new user(); u.LastName = 'Admin'; u.Email = 'test1@test.com'; u.Alias = 'Tcode'; u.Username = 'test123@test.com.testClass'; u.CommunityNickname = 'test121'; u.LocaleSidKey = 'en_US'; u.TimeZoneSidKey = 'GMT'; u.ProfileId = [Select id, name from Profile where name = 'System Administrator' OR name = 'Amministratore del sistema'].id; u.LanguageLocaleKey = 'en_US'; u.EmailEncodingKey = 'UTF-8'; u.IsActive = true; insert u; Date StartDate= Date.newInstance( 2018, 07,1); Date EndDate= Date.newInstance( 2019,10,18 ); String inputValue1= 'test1@test.com'; String inputValue2= testOpportunity.SFDC_Opportunity_Id__c; list<WrapperClassTest> wrp= new list<WrapperClassTest>(); ApexPages.StandardController sc = new ApexPages.StandardController(c); SearchWithWrapperSS x =new SearchWithWrapperSS(); x.loadData(); x.listBD[0].check_box=true; for(WrapperClassTest wTest :wrp) { wTest.check_box=true; } x.changeStatus(); x.processSelected(); x.toSave(); x.toDelete(); Test.stopTest(); } Public class WrapperClassTest{ public Billing_Detail__c cs {get;set;} public Boolean check_box {get;set;} public WrapperClassTest(Billing_Detail__c c, Boolean check_box) { this.cs = c; this.check_box = false; } public WrapperClassTest(Billing_Detail__c c) { this.cs = c; this.check_box = false; } } }
The code coverage is 61% but i don't understand why it's like it doesn't see the content of the inputValue1 and inputValue2.
I'm hoping someone could have a look at my test class and let me know how I should go about passing these parameters.
any help would be appreciated
Thanks
- Frank Carter
- April 07, 2020
- Like
- 0
Unable to Rerender PageBlockTable
Hi Every One,
I have created a Vf page, with inline editing, wrapper class and delete button. When I select records and the delete the page dosen't refresh so I've setted the Rerender on the pageBlock but it does't work. Can someone help me?
vf page
I have created a Vf page, with inline editing, wrapper class and delete button. When I select records and the delete the page dosen't refresh so I've setted the Rerender on the pageBlock but it does't work. Can someone help me?
vf page
<apex:page controller="WrapperDemoControllerBill" lightningStylesheets="true" docType="html-5.0"> <apex:form > <apex:pageBlock title="test" > <apex:commandButton value="Delete" style="text-align:left;" onclick="if(!confirm('If you click ok all the selected billing details will be delated. Are you sure? ')) return false;" action="{!toDelete}" reRender="pb" /> </div> </apex:pageBlock> <apex:pageBlock mode="inlineEdit" id="pb" > <apex:pageBlockSection columns="1" > <apex:pageBlockTable value="{!wpList}" var="wp" > <apex:column headerValue="Action"> <apex:inputCheckbox value="{!wp.check}"/> </apex:column> <apex:column Headervalue="SF OPPORTUNITY ID" > <apex:outputfield value="{!wp.bill.SF_Opportunity_Id__c}"/> </apex:column> <apex:column headervalue="BILLING TYPE"> <apex:outputfield value="{!wp.bill.Billing_Type__c}"/> </apex:column> <apex:column headervalue="BILLING PERIOD"> <apex:outputfield value="{!wp.bill.Billing_Period__c}"/> </apex:column> <apex:column headervalue="MONTHLY FORECAST"> <apex:outputfield value="{!wp.bill.Monthly_Forecast__c}"/> </apex:column> <apex:column headervalue="END OF BILLING"> <apex:outputfield value="{!wp.bill.End_of_Billing__c}"/> </apex:column> <apex:column headervalue="AMOUNT"> <apex:outputfield value="{!wp.bill.Amount__c}"/> </apex:column> <apex:column headervalue="STATUS"> <apex:outputfield value="{!wp.bill.Billing_Status__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}" id="saveButton" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>apex class
public class WrapperDemoControllerBill{ public Billing_Detail__c bil{get;set;} public Date StartDate {get;set;} public Date EndDate {get;set;} public List<Billing_Detail__c> bilList{get;set;} public List<WrapperClass> wpList{get;set;} public WrapperDemoControllerBill(){ wpList = new List<WrapperClass>(); bilList = [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 ]; String bilId = ApexPages.CurrentPage().getParameters().get('id'); if(bilId != null){ bil = [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 id =: bilId limit 1]; }else{ bil = new Billing_Detail__c(); } for(Billing_Detail__c bil : bilList){ WrapperClass wp = new WrapperClass(); wp.bill = bil; wp.check = false; wplist.add(wp); } } public PageReference Save(){ // insert bil; List<Billing_Detail__c> lstBilling = new List<Billing_Detail__c>(); //iterate over wrapper and get all billing for(WrapperClass objWrapper: wpList){ lstBilling.add(objWrapper.bill); } //update list upsert lstBilling; ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'LAST NAME IS MISSING PLEASE ENTER.'); ApexPages.addMessage(myMsg); return null; } public PageReference toDelete(){ // insert bil; List<Billing_Detail__c> lstBilling = new List<Billing_Detail__c>(); //iterate over wrapper and get all billing for(WrapperClass objWrapper: wpList){ if(objWrapper.check==true) lstBilling.add(objWrapper.bill); } //update list delete lstBilling; ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'LAST NAME IS MISSING PLEASE ENTER.'); ApexPages.addMessage(myMsg); return null; } public class WrapperClass{ public Boolean check{get;set;} public Billing_Detail__c bill{get;set;} } }
- Frank Carter
- March 11, 2019
- Like
- 0
visualforce inline editing not saving
Hello,
I have a problem with a VF page. I improved the vf page with the inline editing but I'm not able to save if I edit a record. In a first moment it seems it's saving but if I click the search button the page reload the record without change. I think the problem is in the save method. Can someone hepl me?
Thanks
vf page
Controller
I have a problem with a VF page. I improved the vf page with the inline editing but I'm not able to save if I edit a record. In a first moment it seems it's saving but if I click the search button the page reload the record without change. I think the problem is in the save method. Can someone hepl me?
Thanks
vf page
<apex:page controller="SearchWithWrapperC" lightningStylesheets="true" docType="html-5.0" id="pg"> <script type="text/javascript"> function selectAllCheckboxes(obj,receivedInputID){ var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++){ if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){ inputCheckBox[i].checked = obj.checked; } } } </script> <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 selected billing details will be paid for the current month. Are you sure? ')) return false;" action="{!processSelected}" /> </div> </apex:pageBlock> <apex:pageBlock mode="inlineEdit" id="pgblk" > <apex:pageBlockButtons > <apex:commandbutton value="save" action="{!save1}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" /> </apex:facet> <apex:inputCheckbox value="{!b.check_box}" id="inputId" /> </apex:column> <apex:column Headervalue="SF OPPORTUNITY ID"> <apex:outputfield value="{!b.cs.SF_Opportunity_Id__c}"/> </apex:column> <apex:column headervalue="BILLING TYPE"> <apex:outputfield value="{!b.cs.Billing_Type__c}"/> </apex:column> <apex:column headervalue="BILLING PERIOD" > <apex:outputfield value="{!b.cs.Billing_Period__c}"/> </apex:column> <apex:column headervalue="MONTHLY FORECAST" > <apex:outputfield value="{!b.cs.Monthly_Forecast__c}"/> </apex:column> <apex:column headervalue="END OF BILLING" > <apex:outputfield value="{!b.cs.End_of_Billing__c}"/> </apex:column> <apex:column headervalue="AMOUNT" > <apex:outputfield value="{!b.cs.Amount__c}"/> </apex:column> <apex:column headervalue="BILLING STATUS" > <apex:outputfield value="{!b.cs.Billing_Status__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Controller
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public List<Billing_Detail__c> blst=new List<Billing_Detail__c>(); public List<Billing_Detail__c> getBill(){ blst=[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 blst; } //save method inline editing public void save1() { update blst; } public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); Integer y = Date.Today().Year(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); billlingDetail.Monthly_Forecast__c = Date.newinstance( y , m , bd.cs.Monthly_Forecast__c.day() ); selectedBD.add(billlingDetail); } } update selectedBD; loadData(); return null; } //wrapper public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
- Frank Carter
- March 04, 2019
- Like
- 0
visualforce page reRender PageReference
Hello,
I need HELP, I have a vf search with wrapper class.
There are two buttons, a search button and another to process the selected records.
The problem is when I click the second button the page block is not rerender,but If I click the Search the records are processed.
This second button called, Moves to Next Month, it changes the date with the current month. This method is PageReference.
I tried to apply the reRender on vf page but searching on the forum I read that reRender doesn't works with PageReference method.
How to reRender only results records and not the entire page?
I need to reRender only resuts because I have to date fields to do the research and I don't want to lose the date set.
vf:
controller:
I really need help.
Thanks in advance.
I need HELP, I have a vf search with wrapper class.
There are two buttons, a search button and another to process the selected records.
The problem is when I click the second button the page block is not rerender,but If I click the Search the records are processed.
This second button called, Moves to Next Month, it changes the date with the current month. This method is PageReference.
I tried to apply the reRender on vf page but searching on the forum I read that reRender doesn't works with PageReference method.
How to reRender only results records and not the entire page?
I need to reRender only resuts because I have to date fields to do the research and I don't want to lose the date set.
vf:
<apex:page controller="SearchWithWrapperC" docType="html-5.0" id="pg"> <script type="text/javascript"> function selectAllCheckboxes(obj,receivedInputID){ var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++){ if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){ inputCheckBox[i].checked = obj.checked; } } } </script> <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 selected billing details will be paid for the current month. Are you sure? ')) return false;" action="{!processSelected}" reRender="pagination" /> </div> </apex:pageBlock> <apex:pageBlock id="pagination"> <apex:variable var="listnotnull" value="{!listBD != null}" /> <apex:pageBlockTable value="{!listBD}" var="b" > <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" rendered="{! listnotnull }"/> </apex:facet> <apex:inputCheckbox value="{!b.check_box}" id="inputId" /> </apex:column> <apex:column value="{!b.cs.Name}"/> <apex:column value="{!b.cs.SF_Opportunity_Id__c}"/> <apex:column style="width:110px" value="{!b.cs.Account_Name__c}"/> <apex:column style="width:130px" value="{!b.cs.Billing_Detail__c}"/> <apex:column value="{!b.cs.Billing_Type__c}"/> <apex:column value="{!b.cs.billing_period__c}"/> <apex:column value="{!b.cs.Monthly_Forecast__c}"/> <apex:column value="{!b.cs.End_of_Billing__c}"/> <apex:column value="{!b.cs.Amount__c}"/> <apex:column value="{!b.cs.Billing_Status__c}"/> <apex:column > <apex:outputLink title="" value="/{!b.cs.Id}/e?retURL=/apex/{!$CurrentPage.Name}" target="_blank" style="font-weight:bold">EDIT</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
controller:
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 Account_Name__c, Monthly_Forecast__c]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); billlingDetail.Monthly_Forecast__c = Date.newinstance( bd.cs.Monthly_Forecast__c.year() , m , bd.cs.Monthly_Forecast__c.day() ); selectedBD.add(billlingDetail); } } update selectedBD; return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
I really need help.
Thanks in advance.
- Frank Carter
- October 29, 2018
- Like
- 0
apex method for wrapper class to improve
Hello,
I neeed help.
I created a vf page that show records. I have a method which puts the month of a date field of each record selected to the current month. I have noticed, however, that by selecting more than 40 records, the page gives an error on line 39 (update selectedBD). it takes a long time to process.
I maybe implement logic the wrong way? there is better way?
Can Someone help me?
Thanks
I neeed help.
I created a vf page that show records. I have a method which puts the month of a date field of each record selected to the current month. I have noticed, however, that by selecting more than 40 records, the page gives an error on line 39 (update selectedBD). it takes a long time to process.
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 Account_Name__c, Monthly_Forecast__c]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
I maybe implement logic the wrong way? there is better way?
Can Someone help me?
Thanks
- Frank Carter
- October 26, 2018
- Like
- 0
test class: wrapper class increase code coverage
Hello I have this apex class and I tried to write a good test class. I obtain a 78% code coverage but I want to know what is missing and what I have to do to improve it and to improve my skills on test class.
apex class:
Test class:
Thanks
apex class:
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 Account_Name__c, Monthly_Forecast__c]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
Test class:
@isTest private class SearchWithWrapperCTest { @isTest static void testController() { Test.startTest(); // create the object in input of the class Account a= new Account(); a.name='Account test t'; a.RecordTypeId='012w0000000iROM'; a.Branch__c='Italy'; a.Status__c='Customer'; a.BillingCountry='Italy'; a.Public_Administration_Account__c='No'; insert a; Opportunity testOpportunity = new Opportunity( AccountID = a.Id, Name = 'Test Opportunity', StageName = 'Needs Analysis', CloseDate = date.today().addDays(15) ); insert testOpportunity; Billing_Detail__c c= new Billing_Detail__c(); c.Amount__c= 100; c.Billing_Type__c='FEE'; c.Billing_Period__c='monthly'; c.Billing_Status__c='Authorized for Billing'; c.Product_Line__c='Interactive Experience (iX)'; c.Product__c='Chat Delivery'; c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); c.End_of_Billing__c=Date.newInstance(2019, 7, 9); c.Billing_Detail__c=testOpportunity.Id; insert c; Date StartDate= Date.newInstance( 2018, 10,1); Date EndDate= Date.newInstance( 2018,10,18 ); list<WrapperClassTest> wrp= new list<WrapperClassTest>(); ApexPages.StandardController sc = new ApexPages.StandardController(c); SearchWithWrapperC x =new SearchWithWrapperC(); x.loadData(); x.getBilling(); for(WrapperClassTest wTest :wrp) { wTest.check_box=true; } x.processSelected(); System.assert(wrp.size() > 1); Test.stopTest(); } Public class WrapperClassTest{ public Billing_Detail__c cs {get;set;} public Boolean check_box {get;set;} public WrapperClassTest(Billing_Detail__c c, Boolean check_box) { this.cs = c; this.check_box = false; } } }
Thanks
- Frank Carter
- October 18, 2018
- Like
- 0
hide checkbox select all before search
Hello,
I need help on vf search page. How To do to hide checkbox select all before the search? All the column are hidden except checkbox:
piece of code
Thanks.
I need help on vf search page. How To do to hide checkbox select all before the search? All the column are hidden except checkbox:
piece of code
<apex:pageBlock id="pgblk"> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/> </apex:facet> <apex:inputCheckbox value="{!b.check_box}" id="inputId" /> </apex:column> <apex:column value="{!b.cs.Name}"/>
Thanks.
- Frank Carter
- October 16, 2018
- Like
- 0
wrapper class: method to process selected
Hello,
I need help with a method, processSelected. This method have to change the data in a list of records selected changing only the mont with the current month.
I follow this: https://developer.salesforce.com/page/Wrapper_Class
Controller:
Thanks.
I need help with a method, processSelected. This method have to change the data in a list of records selected changing only the mont with the current month.
I follow this: https://developer.salesforce.com/page/Wrapper_Class
Controller:
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} private Boolean changed {get;set;} public List<WrapperClass> listBD {get;set;} public String SelectedBdId {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c){ this.cs = c; this.check_box = false; } } }vf:
<apex:page controller="SearchWithWrapperC" 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 selected billing details will be paid for the current month. Are you sure? ')) return false;" action="{!processSelected}" /> </div> </apex:pageBlock> <apex:pageBlock id="pgblk"> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column > <apex:inputCheckbox value="{!b.check_box}" /> </apex:column> <apex:column value="{!b.cs.Name}"/> <apex:column value="{!b.cs.SF_Opportunity_Id__c}"/> <apex:column value="{!b.cs.Billing_Type__c}"/> <apex:column value="{!b.cs.Billing_Period__c}"/> <apex:column value="{!b.cs.Monthly_Forecast__c}"/> <apex:column value="{!b.cs.End_of_Billing__c}"/> <apex:column value="{!b.cs.Amount__c}"/> <apex:column value="{!b.cs.Billing_Status__c}"/> <apex:column > <apex:outputLink title="" value="/{!b.cs.Id}/e?retURL=/apex/{!$CurrentPage.Name}" target="_blank" style="font-weight:bold">EDIT</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>The method doesn't work. Can someone help me?
Thanks.
- Frank Carter
- October 16, 2018
- Like
- 0
how to set only the month in a date fields
Hello,
I need help. I have a method that receives a list of custom object. In this object there is a date field already valued. I want update only the month of this date with the current month.
I tried with:
Error: Expression cannot be assigned
Can Someone hepl me?
Thanks,
Francesco
I need help. I have a method that receives a list of custom object. In this object there is a date field already valued. I want update only the month of this date with the current month.
I tried with:
Integer m = Date.Today().Month(); for(Custom_Object__c co: selectedCO) { co.date__c.Month()=m;
Error: Expression cannot be assigned
Can Someone hepl me?
Thanks,
Francesco
- Frank Carter
- October 15, 2018
- Like
- 0
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
- Frank Carter
- October 11, 2018
- Like
- 0
visualforce: redirect to result page
Hello, I need help.
I created a vf search page with two input data fields to set.
When I click the search button the page displays me all the records with a data field included in data range:
If I clicks Edit on a row I have the record page with the three buttons Save, Save and New, Cancel.
If I clicks Save or Edit the result of the search disappears.
The target is that when I go back clicking Cancel or Save I have the same page and not a n empty page:
vf page:
controller:
Thanks
I created a vf search page with two input data fields to set.
When I click the search button the page displays me all the records with a data field included in data range:
If I clicks Edit on a row I have the record page with the three buttons Save, Save and New, Cancel.
If I clicks Save or Edit the result of the search disappears.
The target is that when I go back clicking Cancel or Save I have the same page and not a n empty page:
vf page:
<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, Position__c from Billing_Detail__c Where 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, Position__c from Billing_Detail__c Where 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; } }Can someone give me an help??
Thanks
- Frank Carter
- October 08, 2018
- Like
- 0
visualforce page: <input type="date"/>
Hello, I'm trying to create a vf page and I need some help.
VF page:
I think is not possible use an <input type="date"/> in the controller query.
How I have to do??
Thanks,
Francesco
VF page:
<apex:page controller="searchBDController" docType="html-5.0" id="pg"> <apex:form> <apex:pageBlock> <center><h1>Billing Details Search Page</h1></center> <br/> <br/> <br/> <center> Start Search: <input type="date"/> End Search: <input type="date"/> </center> <br/> <div align="center" draggable="false" > <apex:commandButton value="Reset" action="{!reset}" /> <apex:commandButton value="Search" action="{!loadData}" style="text-align:left;" /> </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:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>Controller:
public class searchBDController { 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, Position__c from Billing_Detail__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, Position__c from Billing_Detail__c ]; } public PageReference reset(){ PageReference pg = new PageReference(System.currentPageReference().getURL()); pg.setRedirect(false); return pg; } }The target is when an user sets two dates and clicks search button the page must give him all the records with Monthly_Forecast__c included between start search and end search <input type="date"/>. These 2 fields are not in the custom object Billing_Detail__c and must not be related with Billing_Detail__c.
I think is not possible use an <input type="date"/> in the controller query.
How I have to do??
Thanks,
Francesco
- Frank Carter
- October 05, 2018
- Like
- 0
override quote button
Hello,
I have a problem, I have the new Quote button but before the creation I have to do some checks on opportunity's fields. If conditions are verified it has to show me a pop up error otherwise it must open the new quote page. I thought about doing it overriding standard new quote with a vf page with inline Javascript. The problem is the vf page have the standar quote controller. How can I get the opportunity record on which I am?
Can someone explain me this? is this a correct approach? there is another way?
Thanks
I have a problem, I have the new Quote button but before the creation I have to do some checks on opportunity's fields. If conditions are verified it has to show me a pop up error otherwise it must open the new quote page. I thought about doing it overriding standard new quote with a vf page with inline Javascript. The problem is the vf page have the standar quote controller. How can I get the opportunity record on which I am?
Can someone explain me this? is this a correct approach? there is another way?
Thanks
- Frank Carter
- September 21, 2018
- Like
- 0
Lightning - list button to delete records
Hello,
I created an object, Billing Detail, for invoices. It's related on opportunity. Every Opportunity won must have one or more billing details. An object Billing detail can be of type PPU(pay for use), UNA TANTUM and FEE(canon). We have several button on related list billing detail on opportunity. "New" to create with a trigger multiple object billing details on that opportunity. Example if we have an annual contract with monthly invoice we can create with one click 12 billing details. The javascript buttons That I want on lightning are: Delete PPu, Delete UNA TANTUM , DElete FEE. THese buttons make a query to delete a type of billing details example If i click "Delete FEE" the button deletes only the billing detail of type FEE except for the FEe in status BILLED. I need this button with this function on lightning. I tried creating a vf page with inside the javascript code but is not working. I want to know waht is the correct approach to have the same button on related list on Lightning?
I created an object, Billing Detail, for invoices. It's related on opportunity. Every Opportunity won must have one or more billing details. An object Billing detail can be of type PPU(pay for use), UNA TANTUM and FEE(canon). We have several button on related list billing detail on opportunity. "New" to create with a trigger multiple object billing details on that opportunity. Example if we have an annual contract with monthly invoice we can create with one click 12 billing details. The javascript buttons That I want on lightning are: Delete PPu, Delete UNA TANTUM , DElete FEE. THese buttons make a query to delete a type of billing details example If i click "Delete FEE" the button deletes only the billing detail of type FEE except for the FEe in status BILLED. I need this button with this function on lightning. I tried creating a vf page with inside the javascript code but is not working. I want to know waht is the correct approach to have the same button on related list on Lightning?
- Frank Carter
- August 27, 2018
- Like
- 0
Lightning: custom button on related list
Hello,
I need help. I have a Javascript button on related list of a custom object and I want to bring this button on Lightning (always on related list).
The Javascript code makes a query to delete all record with certain features.
I know that Javascript button aren't supported in Lightning. I tried created a vf page with standard controller on Custom_Object__c but I'm not able to see the vf paage on dropdown Content.
is my approach wrong?
Thanks,
Frank
I need help. I have a Javascript button on related list of a custom object and I want to bring this button on Lightning (always on related list).
The Javascript code makes a query to delete all record with certain features.
I know that Javascript button aren't supported in Lightning. I tried created a vf page with standard controller on Custom_Object__c but I'm not able to see the vf paage on dropdown Content.
is my approach wrong?
Thanks,
Frank
- Frank Carter
- August 23, 2018
- Like
- 0
vf page/ javascript - return previous page
Hello,
I need help.
I have a custom button on Opportunity record page that opens a vf page with inline Javascript code. I want to know if there is an instruction like "window.location.href = " or similar to make me go back to previous page (valid for Classic and Lightning). The previous page is a page of an opportunity.
Thanks,
Frank
I need help.
I have a custom button on Opportunity record page that opens a vf page with inline Javascript code. I want to know if there is an instruction like "window.location.href = " or similar to make me go back to previous page (valid for Classic and Lightning). The previous page is a page of an opportunity.
<apex:page standardController="Opportunity" > <script type = "text/javascript"> window.onload=function() { if(('{!Opportunity.StageName}' != "Won"){ window.location.href = '/apex/Involve_PreSales?Id={!Opportunity.Id}'; } else alert("The PreSales has already been involved"); //GO TO PREVIOUS PAGE; } }; </script> </apex:page>Can some one help me?
Thanks,
Frank
- Frank Carter
- August 09, 2018
- Like
- 0
Javascript Button to Lightning
Hello,
I need help. I have 2 Javascript Button which opens a visualforce page.
Now the problem is I don't know how to proceed. I read this document but I don't understand Hot to go on.
One of the javascript button code:
I think I have to edit the button to Visualforce Page instead of onclik Javascript. is It Correct?
This code (Javascript) seems like conditions to open the visualforce page. Where I must put this conditions? in Controller of the vf page?
Can anyone help me explaining me how to proceed in this case?
Thanks,
Frank
I need help. I have 2 Javascript Button which opens a visualforce page.
Now the problem is I don't know how to proceed. I read this document but I don't understand Hot to go on.
One of the javascript button code:
if ("{!ISPICKVAL(Opportunity.Demand_Activity_Stage__c,'Involved')}" != "true" && (("{!Opportunity.Opportunity_Type__c}" == "Delivery") || ("{!Opportunity.Opportunity_Type_def__c}" == "Partner") || ("{!Opportunity.Opportunity_Type_def__c}" == "Partner Direct"))) window.location.href = "/apex/Involve_PreSales?Id={!Opportunity.Id}"; //else if ("{!(Opportunity.Opportunity_Type_def__c)}" == 'Partner Direct') //alert("You cannot involve PreSales for Partner Direct Opportunity"); else if ("{!(Opportunity.Demand_Activity_Stage__c)}" == "Involved") alert("The PreSales has already been involved");What I have to do?
I think I have to edit the button to Visualforce Page instead of onclik Javascript. is It Correct?
This code (Javascript) seems like conditions to open the visualforce page. Where I must put this conditions? in Controller of the vf page?
Can anyone help me explaining me how to proceed in this case?
Thanks,
Frank
- Frank Carter
- July 26, 2018
- Like
- 0
apex test class controller
Hello,
I need help. I created a vf page and a controller but now I Have to do the apex test class. This is the first time that I have to do an apex test class for a controller and although I have seen many post and read trailheads I don't understand how to do.
vf page:
controller:
Can someone help me??
Thanks,
Frank
I need help. I created a vf page and a controller but now I Have to do the apex test class. This is the first time that I have to do an apex test class for a controller and although I have seen many post and read trailheads I don't understand how to do.
vf page:
<apex:page controller="BDPaginationController" > <apex:form id="theform" > <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/> <apex:pageBlock id="pbId" title="Billing Details of this Month"> <apex:pageBlockSection collapsible="false" columns="1"> <apex:pageBlockTable value="{!BD}" var="b"> <apex:column > <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink> | <apex:commandLink style="font-weight:bold" action="{!deleteBD}" onclick="if(!confirm('Are you sure you want to delete this record?')) return false;" >Del <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/> </apex:commandLink> | </apex:column> <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 value="{!b.Position__c}"/> <apex:column > <apex:commandLink style="font-weight:bold" action="{!BilledBD}" >Billed <apex:param value="{!b.Id}" name="idToBil" assignTo="{!SelectedBdId}"/> </apex:commandLink> </apex:column> </apex:pageBlockTable> <apex:panelGrid columns="8"> <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();"> <apex:selectOptions value="{!paginationSizeOptions}"/> </apex:selectList> <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords, (setCon.pageNumber * size))} of {!noOfRecords} </apex:outputText> <apex:outputPanel > <apex:actionStatus id="fetchStatus" > <apex:facet name="start" > <img src="/img/loading.gif" /> </apex:facet> </apex:actionStatus> </apex:outputPanel> </apex:panelGrid> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Moves to next month" 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}" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
controller:
public class BDPaginationController{ Public Integer size{get;set;} Public Integer noOfRecords{get; set;} public List<SelectOption> paginationSizeOptions{get;set;} public BDPaginationController(){ size=80; paginationSizeOptions = new List<SelectOption>(); paginationSizeOptions.add(new SelectOption('20','20')); paginationSizeOptions.add(new SelectOption('50','50')); paginationSizeOptions.add(new SelectOption('80','80')); paginationSizeOptions.add(new SelectOption('120','120')); paginationSizeOptions.add(new SelectOption('200','200')); } 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, Position__c from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH Order by Monthly_Forecast__c])); setCon.setPageSize(size); noOfRecords = setCon.getResultSize(); } return setCon; } set; } //Changes the size of pagination public PageReference refreshPageSize() { setCon.setPageSize(size); return null; } // Initialize setCon and return a list of record public List<Billing_Detail__c> getBD() { return (List<Billing_Detail__c>) setCon.getRecords(); } 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, Position__c from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]; } //to delete public PageReference deleteBD(){ DELETE new Billing_Detail__c (Id = SelectedBdId); PageReference pageRef = ApexPages.currentPage(); pageRef.setRedirect(true); return pageRef; } //to move monthly forecast public PageReference myAction(){ MoveBD1.Move1(); PageReference pageRef = ApexPages.currentPage(); pageRef.setRedirect(true); return pageRef; } //to put in billed public PageReference BilledBD(){ Billing_Detail__c bil= new Billing_Detail__c (Id = SelectedBdId); bil.Billing_Status__c='Billed'; update bil; PageReference pageRef = ApexPages.currentPage(); pageRef.setRedirect(true); return pageRef; } }apex class method:
public class MoveBD1 { public static void Move1(){ List <Billing_Detail__c> listBill1= new List <Billing_Detail__c>(); listBill1 = [Select Id,Billing_Detail__c,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 Monthly_Forecast__c=THIS_MONTH]; System.debug('list '+listBill1); for(Billing_Detail__c b1: listBill1){ System.debug('monthly forecast b1'+b1.Monthly_Forecast__c); if(b1.Billing_Status__c!='Billed'){ b1.Monthly_Forecast__c= b1.Monthly_Forecast__c.addMonths(1); System.debug('monthly forecast b1 after '+b1.Monthly_Forecast__c); } } update listBill1; } }
Can someone help me??
Thanks,
Frank
- Frank Carter
- July 23, 2018
- Like
- 0
visualforce page edit/delete error
Hello,
I have a problem with a Visualforce page. I have a controller which aids in displaying a visualforce page with the Edit & Delete functionality. However, my delete doesn't seem to work. When I try to delete, the error is:
The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.
I made a few changes. Now the vf code is:
and the controller code is:
I have 2 errors on developer console:
Thanks,
Frank
I have a problem with a Visualforce page. I have a controller which aids in displaying a visualforce page with the Edit & Delete functionality. However, my delete doesn't seem to work. When I try to delete, the error is:
The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.
I made a few changes. Now the vf code is:
<apex:page controller="BDPaginationController" > <apex:form > <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/> <apex:pageBlock id="pbId" title="Billing Details of this Month"> <apex:pageBlockSection collapsible="false" columns="1"> <apex:pageBlockTable value="{!BD}" var="b"> <apex:column > <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink> | <a href="javascript:if (window.confirm('Are you sure?')) DeleteBD'{!b.Id}');" style="font-weight:bold">Del</a> </apex:column> <apex:column value="{!b.Name}"/> <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:pageBlockTable> <apex:panelGrid columns="8"> <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();"> <apex:selectOptions value="{!paginationSizeOptions}"/> </apex:selectList> <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords, (setCon.pageNumber * size))} of {!noOfRecords} </apex:outputText> <apex:outputPanel > <apex:actionStatus id="fetchStatus" > <apex:facet name="start" > <img src="/img/loading.gif" /> </apex:facet> </apex:actionStatus> </apex:outputPanel> </apex:panelGrid> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Move to next month" action="!next"/> </apex:pageBlockButtons> </apex:pageBlock> //aggiungo <apex:commandLink action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;">Del <apex:param value="{!b.Id}" name="idToDel" assignTo="{!BdId}"/> </apex:commandLink> </apex:form> </apex:page>
and the controller code is:
public class BDPaginationController{ Public Integer size{get;set;} Public Integer noOfRecords{get; set;} public List<SelectOption> paginationSizeOptions{get;set;} public BDPaginationController(){ size=10; paginationSizeOptions = new List<SelectOption>(); paginationSizeOptions.add(new SelectOption('5','5')); paginationSizeOptions.add(new SelectOption('10','10')); paginationSizeOptions.add(new SelectOption('20','20')); paginationSizeOptions.add(new SelectOption('50','50')); paginationSizeOptions.add(new SelectOption('100','100')); } public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ])); setCon.setPageSize(size); noOfRecords = setCon.getResultSize(); } return setCon; } set; } //Changes the size of pagination public PageReference refreshPageSize() { setCon.setPageSize(size); return null; } // Initialize setCon and return a list of record public List<Billing_Detail__c> getBD() { return (List<Billing_Detail__c>) setCon.getRecords(); } public List<Billing_Detail__c> listBD {get;set;} public String SelectedBdId {get;set;} public void loadData() { listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]; } //to delete public void deleteBD(){ listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH AND id =:BdId]; if(listBD.size() > 0 || listBD[0].Id != ''){ delete listBD; } loadData(); } }
I have 2 errors on developer console:
- vf page: Unknown method 'BDPaginationController.deleteBD()' (supposed to the other )
- BDpaginationController: Variable does not exist: BdId
Thanks,
Frank
- Frank Carter
- July 17, 2018
- Like
- 0
apex test class insert help
Hello,
I need help with a test class.I have created an object related to opportunity, “billing detail”.
The result I want to reach is the creation of multiple child object, Billing details, according the number of months that I Have from the difference to “End of billing” and “Created date” divided for a number. The number is 2 if the billing is two-monthly, 1 if is monthly, 3 if is quarterly, 12 for annual. I have an after insert trigger that call an apex class(Helper).
Apex class:
I thought to put into "System.assert.Equals" the length of the listBD(class Helper - CreateBD method) but it doesn't recognize listBD in TestHelper.
Can anyone help me?
Thanks,
Frank
I need help with a test class.I have created an object related to opportunity, “billing detail”.
The result I want to reach is the creation of multiple child object, Billing details, according the number of months that I Have from the difference to “End of billing” and “Created date” divided for a number. The number is 2 if the billing is two-monthly, 1 if is monthly, 3 if is quarterly, 12 for annual. I have an after insert trigger that call an apex class(Helper).
Apex class:
public class Helper { public static void createBD(Billing_Detail__c bd){ List <Billing_Detail__c> listBD = new List <Billing_Detail__c> (); Integer i=0; Integer K=0; if (bd.Billing_Period__c=='two-monthly') { k=2; Date myDate =bd.Monthly_Forecast__c; if(((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='two-monthly'){ i= myDate.monthsBetween(bd.End_of_Billing__c)/2; } for(Integer n =0; n<i-1; n++){//-1 mi serve altrimenti non considerando quella da interfaccia mi crea un'istanza in più if(i!=1){ Billing_Detail__c newBd = new Billing_Detail__c (); newBd.Amount__c=bd.Amount__c; newBd.Billing_Date__c=bd.Billing_Date__c; newBd.Billing_Type__c=bd.Billing_Type__c; newBd.Billing_Status__c=bd.Billing_Status__c; newBd.Billing_Period__c= bd.Billing_Period__c; newBd.Product_Line__c=bd.Product_Line__c; newBd.Product__c=bd.Product__c; newBd.End_of_Billing__c=bd.End_of_Billing__c; newBd.Billing_Detail__c=bd.Billing_Detail__c; newBd.CurrencyIsoCode=bd.CurrencyIsoCode; newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(k); k+=2; listBD.add(newBd); } } insert listBD; } // ripeto le stesso operazioni di prima solo che qui si parla di trimestre quindi divido per 3 else if (bd.Billing_Period__c=='quarterly') { k=3; Date myDate =bd.Monthly_Forecast__c; if (((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='quarterly'){ i= myDate.monthsBetween(bd.End_of_Billing__c)/3; } for(Integer n =0; n<i-1; n++){ if(i!=1){ Billing_Detail__c newBd = new Billing_Detail__c (); newBd.Amount__c=bd.Amount__c; newBd.Billing_Date__c=bd.Billing_Date__c; newBd.Billing_Type__c=bd.Billing_Type__c; newBd.Billing_Status__c=bd.Billing_Status__c; newBd.Billing_Period__c= bd.Billing_Period__c; newBd.Product_Line__c=bd.Product_Line__c; newBd.Product__c=bd.Product__c; newBd.End_of_Billing__c=bd.End_of_Billing__c; newBd.Billing_Detail__c=bd.Billing_Detail__c; newBd.CurrencyIsoCode=bd.CurrencyIsoCode; newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(k);//parametro k per data scalata k+=3; listBD.add(newBd); } } insert listBD; } else if (bd.Billing_Period__c=='annual') { k=12; Date myDate =bd.Monthly_Forecast__c; if (((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='annual'){ i= myDate.monthsBetween(bd.End_of_Billing__c)/12; } for(Integer n =0; n<i-1; n++){ if(i!=1){ Billing_Detail__c newBd = new Billing_Detail__c (); newBd.Amount__c=bd.Amount__c; newBd.Billing_Date__c=bd.Billing_Date__c; newBd.Billing_Type__c=bd.Billing_Type__c; newBd.Billing_Status__c=bd.Billing_Status__c; newBd.Billing_Period__c= bd.Billing_Period__c; newBd.Product_Line__c=bd.Product_Line__c; newBd.Product__c=bd.Product__c; newBd.End_of_Billing__c=bd.End_of_Billing__c; newBd.Billing_Detail__c=bd.Billing_Detail__c; newBd.CurrencyIsoCode=bd.CurrencyIsoCode; newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(k); k+=12; listBD.add(newBd); } } insert listBD; } else if (bd.Billing_Period__c=='monthly'){ Date myDate =bd.Monthly_Forecast__c; if(((bd.Billing_Type__c=='FEE')||(bd.Billing_Type__c=='PPU'))&& bd.Billing_Period__c=='monthly'){ i= myDate.monthsBetween(bd.End_of_Billing__c); System.debug('i='+i); } for(Integer n =0; n<i-1; n++){ if(i!=1){ Billing_Detail__c newBd = new Billing_Detail__c (); System.debug('n='+n); newBd.Amount__c=bd.Amount__c; System.debug('amount'+newBd.Amount__c); newBd.Billing_Date__c=bd.Billing_Date__c; newBd.Billing_Type__c=bd.Billing_Type__c; newBd.Billing_Status__c=bd.Billing_Status__c; newBd.Billing_Period__c= bd.Billing_Period__c; newBd.Product_Line__c=bd.Product_Line__c; newBd.Product__c=bd.Product__c; newBd.End_of_Billing__c=bd.End_of_Billing__c; newBd.Billing_Detail__c=bd.Billing_Detail__c; newBd.CurrencyIsoCode=bd.CurrencyIsoCode; newBd.Monthly_Forecast__c= bd.Monthly_Forecast__c.addMonths(n+1); System.debug('monthly forecast'+newBd.Monthly_Forecast__c); listBD.add(newBd); } } insert listBD; } } }Now I'm trying to create a test class.
@isTest public class testHelper { @isTest static void testcreateBD(){ // create the object in input of the class Helper Billing_Detail__c c= new Billing_Detail__c(); c.Amount__c= 100; c.Billing_Type__c='UNA TANTUM'; c.Billing_Status__c='Authorized for Billing'; c.Product_Line__c='Interactive Experience (iX)'; c.Product__c='Chat Delivery'; c.Monthly_Forecast__ c=Date.newInstance(2018, 7, 9); c.End_of_Billing__c=Date.newInstance(2018, 7, 9); c.Billing_Detail__c='test 1'; c.CurrencyIsoCode='€'; //call Helper class with createBD with c in input Helper.createBD(c); System.assert.Equals( ??? ); } }but I don't understand how to continue.
I thought to put into "System.assert.Equals" the length of the listBD(class Helper - CreateBD method) but it doesn't recognize listBD in TestHelper.
Can anyone help me?
Thanks,
Frank
- Frank Carter
- July 09, 2018
- Like
- 0
problem with test class for search page
hi, I'm hoping someone can point me in the right direction.
I have a vf page to search child object related to Opportunity.
In input user have to insert two string Inputtext (owner and id opportunity).
In apex class there is a void method load data:
Apex class:
the test class:
The code coverage is 61% but i don't understand why it's like it doesn't see the content of the inputValue1 and inputValue2.
I'm hoping someone could have a look at my test class and let me know how I should go about passing these parameters.
any help would be appreciated
Thanks
I have a vf page to search child object related to Opportunity.
In input user have to insert two string Inputtext (owner and id opportunity).
In apex class there is a void method load data:
Apex class:
public class SearchWithWrapperSS { public Date StartDate {get;set;} public Date EndDate {get;set;} public String inputValue1 {get;set;} public String inputValue2 {get;set;} public List<WrapperClass> listBD {get;set;} public List<Billing_Detail__c> blst=new List<Billing_Detail__c>(); public void loadData() { if ((! String.isBlank(inputValue1))&&(String.isBlank(inputValue2))){ String Owner; List <User> userList = [Select id, Name from User where Email =: inputValue1]; if(! userList.isEmpty()){ Owner = userList[0].id; List <Billing_Detail__c> billingList = [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Detail__c IN (select id from Opportunity where OwnerId=:Owner)and Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]; listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : billingList ){ listBD.add(new WrapperClass (cr, false)); } } } else if ((! String.isBlank(inputValue1))&&(! String.isBlank(inputValue2))){ String Owner; List <User> userList = [Select id, Name from User where Email =: inputValue1]; if(! userList.isEmpty()){ Owner = userList[0].id; List <Billing_Detail__c> listBilling = [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Detail__c IN (select id from Opportunity where OwnerId=:Owner) and Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and SF_Opportunity_Id__c=:inputValue2 and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]; listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : listBilling){ listBD.add(new WrapperClass (cr, false)); } } } else if (! String.isBlank(inputValue2)){ listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and SF_Opportunity_Id__c=:inputValue2 and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } else{ listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,Account_Name__c,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,Billing_Competence_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate and Billing_Status__c !='Billed' Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference changeStatus() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); billlingDetail.Billing_Status__c= 'Authorized for Billing'; selectedBD.add(billlingDetail); } } update selectedBD; loadData(); return null; } public PageReference processSelected() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); if (bd.cs.Monthly_Forecast__c.month()==12) { billlingDetail.Monthly_Forecast__c = Date.newinstance( bd.cs.Monthly_Forecast__c.year()+1 , 01 , bd.cs.Monthly_Forecast__c.day() ); billlingDetail.Billing_Competence_Forecast__c = billlingDetail.Monthly_Forecast__c; selectedBD.add(billlingDetail); } else{ billlingDetail.Monthly_Forecast__c = Date.newinstance( bd.cs.Monthly_Forecast__c.year() , bd.cs.Monthly_Forecast__c.month()+1, bd.cs.Monthly_Forecast__c.day() ); billlingDetail.Billing_Competence_Forecast__c = billlingDetail.Monthly_Forecast__c; selectedBD.add(billlingDetail); } } } update selectedBD; loadData(); return null; } //save public PageReference toSave() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; billlingDetail = new Billing_Detail__c(Id=bd.cs.Id,Amount__c=bd.cs.Amount__c, Billing_Type__c=bd.cs.Billing_Type__c,Billing_Competence_Forecast__c=bd.cs.Billing_Competence_Forecast__c, Billing_Period__c=bd.cs.Billing_Period__c, Billing_Status__c=bd.cs.Billing_Status__c, Monthly_Forecast__c=bd.cs.Monthly_Forecast__c,End_of_Billing__c=bd.cs.End_of_Billing__c ); selectedBD.add(billlingDetail); } update selectedBD; loadData(); return null; } public PageReference toDelete() { List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); selectedBD.add(billlingDetail); } } delete selectedBD; loadData(); return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
the test class:
@isTest private class SearchWithWrapperSSTest { @isTest static void testController() { Test.startTest(); Id RecordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Customer_user').getRecordTypeId();//get only macrostructure RT // create the object in input of the class Account a= new Account(); a.name='Account test t'; //a.RecordTypeId='012w0000000iROM'; a.Branch__c='Italy'; a.Status__c='Customer'; a.BillingCountry='Italy'; a.Public_Administration_Account__c='No'; insert a; Opportunity testOpportunity = new Opportunity( AccountID = a.Id, Name = 'Test Opportunity', StageName = 'Needs Analysis', CloseDate = date.today().addDays(15) ); insert testOpportunity; Billing_Detail__c c= new Billing_Detail__c(); c.Amount__c= 100; c.Billing_Type__c='FEE'; c.Billing_Period__c='monthly'; c.Billing_Status__c='Authorized for Billing'; c.Product_Line__c='Interactive Experience (iX)'; c.Product__c='Chat Delivery'; c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); c.End_of_Billing__c=Date.newInstance(2019, 7, 9); c.Billing_Detail__c=testOpportunity.Id; insert c; User u = new user(); u.LastName = 'Admin'; u.Email = 'test1@test.com'; u.Alias = 'Tcode'; u.Username = 'test123@test.com.testClass'; u.CommunityNickname = 'test121'; u.LocaleSidKey = 'en_US'; u.TimeZoneSidKey = 'GMT'; u.ProfileId = [Select id, name from Profile where name = 'System Administrator' OR name = 'Amministratore del sistema'].id; u.LanguageLocaleKey = 'en_US'; u.EmailEncodingKey = 'UTF-8'; u.IsActive = true; insert u; Date StartDate= Date.newInstance( 2018, 07,1); Date EndDate= Date.newInstance( 2019,10,18 ); String inputValue1= 'test1@test.com'; String inputValue2= testOpportunity.SFDC_Opportunity_Id__c; list<WrapperClassTest> wrp= new list<WrapperClassTest>(); ApexPages.StandardController sc = new ApexPages.StandardController(c); SearchWithWrapperSS x =new SearchWithWrapperSS(); x.loadData(); x.listBD[0].check_box=true; for(WrapperClassTest wTest :wrp) { wTest.check_box=true; } x.changeStatus(); x.processSelected(); x.toSave(); x.toDelete(); Test.stopTest(); } Public class WrapperClassTest{ public Billing_Detail__c cs {get;set;} public Boolean check_box {get;set;} public WrapperClassTest(Billing_Detail__c c, Boolean check_box) { this.cs = c; this.check_box = false; } public WrapperClassTest(Billing_Detail__c c) { this.cs = c; this.check_box = false; } } }
The code coverage is 61% but i don't understand why it's like it doesn't see the content of the inputValue1 and inputValue2.
I'm hoping someone could have a look at my test class and let me know how I should go about passing these parameters.
any help would be appreciated
Thanks
- Frank Carter
- April 07, 2020
- Like
- 0
visualforce inline editing not saving
Hello,
I have a problem with a VF page. I improved the vf page with the inline editing but I'm not able to save if I edit a record. In a first moment it seems it's saving but if I click the search button the page reload the record without change. I think the problem is in the save method. Can someone hepl me?
Thanks
vf page
Controller
I have a problem with a VF page. I improved the vf page with the inline editing but I'm not able to save if I edit a record. In a first moment it seems it's saving but if I click the search button the page reload the record without change. I think the problem is in the save method. Can someone hepl me?
Thanks
vf page
<apex:page controller="SearchWithWrapperC" lightningStylesheets="true" docType="html-5.0" id="pg"> <script type="text/javascript"> function selectAllCheckboxes(obj,receivedInputID){ var inputCheckBox = document.getElementsByTagName("input"); for(var i=0; i<inputCheckBox.length; i++){ if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){ inputCheckBox[i].checked = obj.checked; } } } </script> <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 selected billing details will be paid for the current month. Are you sure? ')) return false;" action="{!processSelected}" /> </div> </apex:pageBlock> <apex:pageBlock mode="inlineEdit" id="pgblk" > <apex:pageBlockButtons > <apex:commandbutton value="save" action="{!save1}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" /> </apex:facet> <apex:inputCheckbox value="{!b.check_box}" id="inputId" /> </apex:column> <apex:column Headervalue="SF OPPORTUNITY ID"> <apex:outputfield value="{!b.cs.SF_Opportunity_Id__c}"/> </apex:column> <apex:column headervalue="BILLING TYPE"> <apex:outputfield value="{!b.cs.Billing_Type__c}"/> </apex:column> <apex:column headervalue="BILLING PERIOD" > <apex:outputfield value="{!b.cs.Billing_Period__c}"/> </apex:column> <apex:column headervalue="MONTHLY FORECAST" > <apex:outputfield value="{!b.cs.Monthly_Forecast__c}"/> </apex:column> <apex:column headervalue="END OF BILLING" > <apex:outputfield value="{!b.cs.End_of_Billing__c}"/> </apex:column> <apex:column headervalue="AMOUNT" > <apex:outputfield value="{!b.cs.Amount__c}"/> </apex:column> <apex:column headervalue="BILLING STATUS" > <apex:outputfield value="{!b.cs.Billing_Status__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Controller
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public List<Billing_Detail__c> blst=new List<Billing_Detail__c>(); public List<Billing_Detail__c> getBill(){ blst=[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 blst; } //save method inline editing public void save1() { update blst; } public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); Integer y = Date.Today().Year(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ Billing_Detail__c billlingDetail ; if(bd.check_box== true){ billlingDetail = new Billing_Detail__c(Id=bd.cs.Id); billlingDetail.Monthly_Forecast__c = Date.newinstance( y , m , bd.cs.Monthly_Forecast__c.day() ); selectedBD.add(billlingDetail); } } update selectedBD; loadData(); return null; } //wrapper public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
- Frank Carter
- March 04, 2019
- Like
- 0
apex method for wrapper class to improve
Hello,
I neeed help.
I created a vf page that show records. I have a method which puts the month of a date field of each record selected to the current month. I have noticed, however, that by selecting more than 40 records, the page gives an error on line 39 (update selectedBD). it takes a long time to process.
I maybe implement logic the wrong way? there is better way?
Can Someone help me?
Thanks
I neeed help.
I created a vf page that show records. I have a method which puts the month of a date field of each record selected to the current month. I have noticed, however, that by selecting more than 40 records, the page gives an error on line 39 (update selectedBD). it takes a long time to process.
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 Account_Name__c, Monthly_Forecast__c]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
I maybe implement logic the wrong way? there is better way?
Can Someone help me?
Thanks
- Frank Carter
- October 26, 2018
- Like
- 0
test class: wrapper class increase code coverage
Hello I have this apex class and I tried to write a good test class. I obtain a 78% code coverage but I want to know what is missing and what I have to do to improve it and to improve my skills on test class.
apex class:
Test class:
Thanks
apex class:
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 Account_Name__c, Monthly_Forecast__c]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__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 ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
Test class:
@isTest private class SearchWithWrapperCTest { @isTest static void testController() { Test.startTest(); // create the object in input of the class Account a= new Account(); a.name='Account test t'; a.RecordTypeId='012w0000000iROM'; a.Branch__c='Italy'; a.Status__c='Customer'; a.BillingCountry='Italy'; a.Public_Administration_Account__c='No'; insert a; Opportunity testOpportunity = new Opportunity( AccountID = a.Id, Name = 'Test Opportunity', StageName = 'Needs Analysis', CloseDate = date.today().addDays(15) ); insert testOpportunity; Billing_Detail__c c= new Billing_Detail__c(); c.Amount__c= 100; c.Billing_Type__c='FEE'; c.Billing_Period__c='monthly'; c.Billing_Status__c='Authorized for Billing'; c.Product_Line__c='Interactive Experience (iX)'; c.Product__c='Chat Delivery'; c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); c.End_of_Billing__c=Date.newInstance(2019, 7, 9); c.Billing_Detail__c=testOpportunity.Id; insert c; Date StartDate= Date.newInstance( 2018, 10,1); Date EndDate= Date.newInstance( 2018,10,18 ); list<WrapperClassTest> wrp= new list<WrapperClassTest>(); ApexPages.StandardController sc = new ApexPages.StandardController(c); SearchWithWrapperC x =new SearchWithWrapperC(); x.loadData(); x.getBilling(); for(WrapperClassTest wTest :wrp) { wTest.check_box=true; } x.processSelected(); System.assert(wrp.size() > 1); Test.stopTest(); } Public class WrapperClassTest{ public Billing_Detail__c cs {get;set;} public Boolean check_box {get;set;} public WrapperClassTest(Billing_Detail__c c, Boolean check_box) { this.cs = c; this.check_box = false; } } }
Thanks
- Frank Carter
- October 18, 2018
- Like
- 0
hide checkbox select all before search
Hello,
I need help on vf search page. How To do to hide checkbox select all before the search? All the column are hidden except checkbox:
piece of code
Thanks.
I need help on vf search page. How To do to hide checkbox select all before the search? All the column are hidden except checkbox:
piece of code
<apex:pageBlock id="pgblk"> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column > <apex:facet name="header"> <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/> </apex:facet> <apex:inputCheckbox value="{!b.check_box}" id="inputId" /> </apex:column> <apex:column value="{!b.cs.Name}"/>
Thanks.
- Frank Carter
- October 16, 2018
- Like
- 0
wrapper class: method to process selected
Hello,
I need help with a method, processSelected. This method have to change the data in a list of records selected changing only the mont with the current month.
I follow this: https://developer.salesforce.com/page/Wrapper_Class
Controller:
Thanks.
I need help with a method, processSelected. This method have to change the data in a list of records selected changing only the mont with the current month.
I follow this: https://developer.salesforce.com/page/Wrapper_Class
Controller:
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} private Boolean changed {get;set;} public List<WrapperClass> listBD {get;set;} public String SelectedBdId {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [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 ]){ listBD.add(new WrapperClass (cr, false)); } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c){ this.cs = c; this.check_box = false; } } }vf:
<apex:page controller="SearchWithWrapperC" 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 selected billing details will be paid for the current month. Are you sure? ')) return false;" action="{!processSelected}" /> </div> </apex:pageBlock> <apex:pageBlock id="pgblk"> <apex:pageBlockTable value="{!listBD}" var="b"> <apex:column > <apex:inputCheckbox value="{!b.check_box}" /> </apex:column> <apex:column value="{!b.cs.Name}"/> <apex:column value="{!b.cs.SF_Opportunity_Id__c}"/> <apex:column value="{!b.cs.Billing_Type__c}"/> <apex:column value="{!b.cs.Billing_Period__c}"/> <apex:column value="{!b.cs.Monthly_Forecast__c}"/> <apex:column value="{!b.cs.End_of_Billing__c}"/> <apex:column value="{!b.cs.Amount__c}"/> <apex:column value="{!b.cs.Billing_Status__c}"/> <apex:column > <apex:outputLink title="" value="/{!b.cs.Id}/e?retURL=/apex/{!$CurrentPage.Name}" target="_blank" style="font-weight:bold">EDIT</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>The method doesn't work. Can someone help me?
Thanks.
- Frank Carter
- October 16, 2018
- Like
- 0
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
- Frank Carter
- October 11, 2018
- Like
- 0
visualforce: redirect to result page
Hello, I need help.
I created a vf search page with two input data fields to set.
When I click the search button the page displays me all the records with a data field included in data range:
If I clicks Edit on a row I have the record page with the three buttons Save, Save and New, Cancel.
If I clicks Save or Edit the result of the search disappears.
The target is that when I go back clicking Cancel or Save I have the same page and not a n empty page:
vf page:
controller:
Thanks
I created a vf search page with two input data fields to set.
When I click the search button the page displays me all the records with a data field included in data range:
If I clicks Edit on a row I have the record page with the three buttons Save, Save and New, Cancel.
If I clicks Save or Edit the result of the search disappears.
The target is that when I go back clicking Cancel or Save I have the same page and not a n empty page:
vf page:
<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, Position__c from Billing_Detail__c Where 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, Position__c from Billing_Detail__c Where 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; } }Can someone give me an help??
Thanks
- Frank Carter
- October 08, 2018
- Like
- 0
visualforce page: <input type="date"/>
Hello, I'm trying to create a vf page and I need some help.
VF page:
I think is not possible use an <input type="date"/> in the controller query.
How I have to do??
Thanks,
Francesco
VF page:
<apex:page controller="searchBDController" docType="html-5.0" id="pg"> <apex:form> <apex:pageBlock> <center><h1>Billing Details Search Page</h1></center> <br/> <br/> <br/> <center> Start Search: <input type="date"/> End Search: <input type="date"/> </center> <br/> <div align="center" draggable="false" > <apex:commandButton value="Reset" action="{!reset}" /> <apex:commandButton value="Search" action="{!loadData}" style="text-align:left;" /> </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:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>Controller:
public class searchBDController { 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, Position__c from Billing_Detail__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, Position__c from Billing_Detail__c ]; } public PageReference reset(){ PageReference pg = new PageReference(System.currentPageReference().getURL()); pg.setRedirect(false); return pg; } }The target is when an user sets two dates and clicks search button the page must give him all the records with Monthly_Forecast__c included between start search and end search <input type="date"/>. These 2 fields are not in the custom object Billing_Detail__c and must not be related with Billing_Detail__c.
I think is not possible use an <input type="date"/> in the controller query.
How I have to do??
Thanks,
Francesco
- Frank Carter
- October 05, 2018
- Like
- 0
override quote button
Hello,
I have a problem, I have the new Quote button but before the creation I have to do some checks on opportunity's fields. If conditions are verified it has to show me a pop up error otherwise it must open the new quote page. I thought about doing it overriding standard new quote with a vf page with inline Javascript. The problem is the vf page have the standar quote controller. How can I get the opportunity record on which I am?
Can someone explain me this? is this a correct approach? there is another way?
Thanks
I have a problem, I have the new Quote button but before the creation I have to do some checks on opportunity's fields. If conditions are verified it has to show me a pop up error otherwise it must open the new quote page. I thought about doing it overriding standard new quote with a vf page with inline Javascript. The problem is the vf page have the standar quote controller. How can I get the opportunity record on which I am?
Can someone explain me this? is this a correct approach? there is another way?
Thanks
- Frank Carter
- September 21, 2018
- Like
- 0