You need to sign in to do that
Don't have an account?
How to make my wrapper class access record. - Please Help
Hi There,
I have a wrapper class, it is used to create a finance__c record and multiple children finance loan split and finance Loan securities. This allows me to save at once and they are all joined.
I am attempting to make it so that the controller can be used to edit the same records. I have a roundabout idea of what I am meant to do....I have evn been able to access the main Fin record, however every attempt I have made at filling the wrapper list when accessing a record (rather than inserting)...I always get no results. Please can someone point me in the right direction of how I might access a list of already created Finance Loan split records and display them in my datatable.
thank you in advance for your time. My controller is below:
public class FinanceNew2{ public Finance__c Fin { get; set; } public Finance_Loan_Security__c LoanSecurity { get; set; } public Finance_Loan_Split__c LoanSplit { get; set; } //Wrapper multi add try to implement public List<FinLoanSplitWrapper> wrappers {get; set;} public static Integer toDelIdent {get; set;} public static Integer addCount {get; set;} private Integer nextIdent=0; //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Wrapper 2 identical - 1 public List<FinLoanSecurityWrapper> wrappers2 {get; set;} public static Integer toDelIdent2 {get; set;} public static Integer addCount2 {get; set;} private Integer nextIdent2=0; //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Wrapper 2 identical - 1 Id FinId = ApexPages.currentPage().getParameters().get('FinId'); ////////////////test public decimal AggregateLoanAmount{get;set;} public integer LoanSplitSize{get;set;} public void calculation() { AggregateLoanAmount = 0.00; LoanSplitSize = 0; for (FinLoanSplitWrapper wrap : wrappers) { if(wrap.FinLoanS.Loan_Amount__c == null){ wrap.FinLoanS.Loan_Amount__c = 0.00; } LoanSplitSize = LoanSplitSize + 1; AggregateLoanAmount = AggregateLoanAmount + wrap.FinLoanS.Loan_Amount__c; } Fin.Number_of_Securities__c = LoanSplitSize; } ////////////////test ////////////////////Delete Rows //Delete Rows 1 public void delWrapper() { Integer toDelPos=-1; for (Integer idx=0; idx<wrappers.size(); idx++) { if (wrappers[idx].ident==toDelIdent) { toDelPos=idx; } } if (-1!=toDelPos) { wrappers.remove(toDelPos); } } //Delete Rows 2 public void delWrapper2() { Integer toDelPos=-1; for (Integer idx=0; idx<wrappers2.size(); idx++) { if (wrappers2[idx].ident2==toDelIdent2) { toDelPos=idx; } } if (-1!=toDelPos) { wrappers2.remove(toDelPos); } } //////////////////////////Add Rows //Add Rows 1 public void addRows() { for (Integer idx=0; idx<addCount; idx++) { wrappers.add(new FinLoanSplitWrapper(nextIdent++, null)); } } //Add Rows 2 public void addRows2() { for (Integer idx=0; idx<addCount2; idx++) { wrappers2.add(new FinLoanSecurityWrapper(nextIdent2++)); } } //////////////////////////Add Rows ////////////////Wrappers public class FinLoanSplitWrapper { public Finance_Loan_Split__c FinLoanS {get; private set;} public Integer ident {get; private set;} public FinLoanSplitWrapper(Integer inIdent , Finance_Loan_Split__c LoanSplit) { Id FinId = ApexPages.currentPage().getParameters().get('FinId'); if(LoanSplit!= null){ FinLoans = LoanSplit; ident=integer.valueof(LoanSplit.Loan_Split_Number__c); }else{ FinLoanS=new Finance_Loan_Split__c(Loan_Split_Number__c=ident); } } } public class FinLoanSecurityWrapper { public Finance_Loan_Security__c FinSecS {get; private set;} public Integer ident2 {get; private set;} public FinLoanSecurityWrapper(Integer inIdent) { ident2=inIdent; FinSecS=new Finance_Loan_Security__c(Loan_Security_Number__c=ident2); } } ////////////////Wrappers //Wrapper multi add try to implement /* public List<FinLoanSplitWrapper> getWrappers() { Id FinId = ApexPages.currentPage().getParameters().get('FinId'); if(FinId != null){ if(wrappers == null) { wrappers=new List<FinLoanSplitWrapper>(); for(Finance_Loan_Split__c LoanSplit:[SELECT Id, Account__c ,Office__c, Loan_Split_Number__c, Loan_Amount__c ,Loan_Type__c,Payment_Type__c, Loan_Purpose__c,Comment__c FROM Finance_Loan_Split__c WHERE Id = :FinId]){ wrappers.add(new FinLoanSplitWrapper((integer.valueof(LoanSplit.Loan_Split_Number__c)),LoanSplit)); } } } return wrappers; } */ public FinanceNew2() { Id FinId = ApexPages.currentPage().getParameters().get('FinId'); if(FinId != null){ Fin = [SELECT Id, Application_End_Reason__c, Financier__c, Financier_Reference__c, Application_LVR__c , Total_Security_Value__c, Loan_Information__c , Account__c , Finance_Office__c, Settlement_Due__c, Finance_Clause__c, Number_of_Securities__c FROM Finance__c WHERE Id = :ApexPages.currentPage().getParameters().get('FinId')]; if(wrappers == null) { wrappers=new List<FinLoanSplitWrapper>(); for(Finance_Loan_Split__c LoanSplit:[SELECT Id, Account__c ,Office__c, Loan_Split_Number__c FROM Finance_Loan_Split__c WHERE Id = :FinId]){ wrappers.add(new FinLoanSplitWrapper(null,LoanSplit)); } } List<Finance_Loan_Security__c> LoanSecurity = [SELECT Id, Account__c ,Office__c FROM Finance_Loan_Security__c WHERE Id = :FinId]; wrappers2=new List<FinLoanSecurityWrapper>(); for (Integer idx=0; idx<1; idx++) { wrappers2.add(new FinLoanSecurityWrapper(nextIdent2++)); } }else{ Fin = new Finance__c (); Fin.Finance_Office__c = ApexPages.currentPage().getParameters().get('OffId'); Fin.Account__c = ApexPages.currentPage().getParameters().get('AccId'); //LoanSecurity = new Finance_Loan_Security__c (); wrappers=new List<FinLoanSplitWrapper>(); for (Integer idx=0; idx<1; idx++) { wrappers.add(new FinLoanSplitWrapper(nextIdent++, null)); } wrappers2=new List<FinLoanSecurityWrapper>(); for (Integer idx=0; idx<1; idx++) { wrappers2.add(new FinLoanSecurityWrapper(nextIdent2++)); } } } //////////////////////////Save and Cancel\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ public PageReference saveStandard() { Fin.Aggregate_Borrowings__c = AggregateLoanAmount; try { upsert Fin; } catch (Exception e) { ApexPages.addMessages(e); } List<Finance_Loan_Split__c> FLS =new List<Finance_Loan_Split__c>(); for (FinLoanSplitWrapper wrap : wrappers) { FLS.add(wrap.FinLoanS); } List<Finance_Loan_Security__c> LoanSecurity =new List<Finance_Loan_Security__c>(); for (FinLoanSecurityWrapper wrap : wrappers2) { LoanSecurity.add(wrap.FinSecS); } for (Finance_Loan_Split__c FinLoanSplit: FLS) { FinLoanSplit.Finance__c = Fin.id; FinLoanSplit.Account__c = Fin.Account__c; FinLoanSplit.Office__c = Fin.Finance_Office__c; } for (Finance_Loan_Security__c LoanSec: LoanSecurity) { LoanSec.Finance__c = Fin.id; LoanSec.Account__c = Fin.Account__c; LoanSec.Office__c = Fin.Finance_Office__c; } try { upsert FLS; upsert LoanSecurity; PageReference pageRef= new PageReference('/apex/DestinyAccount?id='+fin.Account__c+'&Sfdc.override=1'); return pageRef; } catch (Exception e) { ApexPages.addMessages(e); } return null; } public PageReference Cancel() { PageReference pageRef= new PageReference('/apex/DestinyAccount?id='+Fin.account__c+'&Sfdc.override=1'); return pageRef; } //////////////////////////Save and Cancel\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //////////////////////Old Code to keep for Reference - Delete Later\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ /* Remove for now, keep for ref public PageReference save2() { List<Finance_Loan_Security__c> LoanSecurity =new List<Finance_Loan_Security__c>(); for (FinLoanSecurityWrapper wrap : wrappers2) { LoanSecurity.add(wrap.FinSecS); } insert LoanSecurity; return new PageReference('/' + Schema.getGlobalDescribe().get('Finance_Loan_Split__c').getDescribe().getKeyPrefix() + '/o'); } */ /* Remove for now, as it has been made redunant. keep for reference incase soemthing goes wrong public PageReference save() { List<Finance_Loan_Split__c> FLS =new List<Finance_Loan_Split__c>(); for (FinLoanSplitWrapper wrap : wrappers) { FLS.add(wrap.FinLoanS); } insert FLS; return new PageReference('/' + Schema.getGlobalDescribe().get('Finance_Loan_Split__c').getDescribe().getKeyPrefix() + '/o'); } */ //////////////////////Old Code to keep for Reference - Delete Later\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ }
Please see the below sample code which dislays the wrapper class which accesses the object records and also presents them on the screen.
Please follow the below link for more info
https://developer.salesforce.com/page/Wrapper_Class
Best Regards
Naga Kiran
I manmaged to get it working, but still some issues with adding new rows. This is how i got it working: