You need to sign in to do that
Don't have an account?
Apex / Visualforce : User input for Wrapper Class
Hello guys,
this apex class includes one wrapper class (cBoost). With the cBoost object and a visualforce page the user is able to select Finalboost records. After the user selection, the class generates XtraBoostOpp__c records. Now, i want to provide a option for the user to create a integer value for each selected FinalBoost record. In the save methode i want to create the XtraBoostOpp__c records and assign the integer value.
In my opinion, i have to create a new variable in my wrapper class (cBoost.menge) . I have tried different ways but nothing worked....
The api name of the XtraBoostOpp__c field is 'Menge__c' .
Thanks for your help guys !
this apex class includes one wrapper class (cBoost). With the cBoost object and a visualforce page the user is able to select Finalboost records. After the user selection, the class generates XtraBoostOpp__c records. Now, i want to provide a option for the user to create a integer value for each selected FinalBoost record. In the save methode i want to create the XtraBoostOpp__c records and assign the integer value.
In my opinion, i have to create a new variable in my wrapper class (cBoost.menge) . I have tried different ways but nothing worked....
The api name of the XtraBoostOpp__c field is 'Menge__c' .
public class CreateMultiExtraBoost { public List<cBoost> boostList {get; set;} public Id opportunityId {get;set;} // Constructor public CreateMultiExtraBoost (){ opportunityId = ApexPages.currentPage().getparameters().get('oppId'); } //Methode public List<cBoost> getBoosts() { if(boostList == null) { boostList = new List<cBoost>(); for(FinalBoost__c fb: [select Id, Name from FinalBoost__c ]) { boostList.add(new cBoost(fb)); } } return boostList; } public PageReference save() { List<FinalBoost__c> selectedBoosts = new List <FinalBoost__c>(); List<XtraBoostOpp__c> boostItems = new List <XtraBoostOpp__c>(); pagereference oppPage = new pagereference('/' + opportunityId); for(cBoost cbInList: getBoosts ()) { if(cbInList.selected == true ) { selectedBoosts.add(cbInList.fbo); } } System.debug('These are the selected ...'); for(FinalBoost__c con: selectedBoosts) { system.debug(con); } for (FinalBoost__c fboInList: selectedBoosts) { XtraBoostOpp__c boost = new XtraBoostOpp__c (); boost.FinalBoost__c = fboInList.Id; boost.Opportunity__c = opportunityId; boost.Menge__c = //user input variable boostItems.add(boost); } insert boostItems; return oppPage; } // WrapperClass public class cBoost { public FinalBoost__c fbo {get; set;} public Boolean selected {get; set;} public Integer menge {get; set;} // user input variable //WrapperClass Constructor public cBoost(FinalBoost__c f) { this.fbo = f; this.selected = false; this.menge = 0; } } }
Thanks for your help guys !
XtraBoostOpp__c boost = new XtraBoostOpp__c ();
boost.FinalBoost__c = fboInList.Id;
boost.Opportunity__c = opportunityId;
boost.Menge__c = cbInList.menge //user input variable
boostItems.add(boost);
to
XtraBoostOpp__c boost = new XtraBoostOpp__c ();
boost.FinalBoost__c = cbInList.fbo.Id;
boost.Opportunity__c = opportunityId;
boost.Menge__c = cbInList.menge //user input variable
boostItems.add(boost);
All Answers
for(cBoost cbInList: getBoosts ()) {
if(cbInList.selected == true ) {
//selectedBoosts.add(cbInList.fbo);
XtraBoostOpp__c boost = new XtraBoostOpp__c ();
boost.FinalBoost__c = fboInList.Id;
boost.Opportunity__c = opportunityId;
boost.Menge__c = cbInList.menge //user input variable
boostItems.add(boost);
}
}
System.debug('These are the selected ...');
/*for(FinalBoost__c con: selectedBoosts) {
system.debug(con);
}
for (FinalBoost__c fboInList: selectedBoosts) {
XtraBoostOpp__c boost = new XtraBoostOpp__c ();
boost.FinalBoost__c = fboInList.Id;
boost.Opportunity__c = opportunityId;
boost.Menge__c = //user input variable
boostItems.add(boost);
} */
insert boostItems;
return oppPage;
Please let me know if you still face any issue in this, If it solves your issue mark it as solved.
XtraBoostOpp__c boost = new XtraBoostOpp__c ();
boost.FinalBoost__c = fboInList.Id;
boost.Opportunity__c = opportunityId;
boost.Menge__c = cbInList.menge //user input variable
boostItems.add(boost);
to
XtraBoostOpp__c boost = new XtraBoostOpp__c ();
boost.FinalBoost__c = cbInList.fbo.Id;
boost.Opportunity__c = opportunityId;
boost.Menge__c = cbInList.menge //user input variable
boostItems.add(boost);
thanks for your quick response. Your code works ! I know, that i can do the class without the selected List but in this case like the way to create multiple lists. Is there a way to push the variable cbInList.menge in the selected list ?