You need to sign in to do that
Don't have an account?
Sandra Wicket
Create a child record for each parent record in the list
Hi Guys,
this is my code :
A visualforcepage shows the table of FinalBoost records. I can select records and use them in the save methode. The BoostOpp__c object is a junction object. It is related to the opportunity and the FinalBoost Object.
In my loop, i want to create for each selected record one child record and assign the parent id (FinalBoost) to the masterDetail field. At the moment, it creates for each selection one record but allways with the same finalBoostId. Is there a simple solution for that ?
Cheers Sandra
this is my code :
public class CreateMultiExtraBoost { public List<cBoost> boostList {get; set;} Integer listSize {get;set;} public Id opportunityId {get;set;} public ID finalBoostId {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 c: [select Id, Name from FinalBoost__c ]) { boostList.add(new cBoost(c)); } } return boostList; } public PageReference save() { List<FinalBoost__c> selectedContacts = new List <FinalBoost__c>(); List<BoostOpp__c> boostItems = new List <BoostOpp__c>(); pagereference oppPage = new pagereference('/' + opportunityId); for(cBoost cCon: getBoosts ()) { if(cCon.selected == true ) { selectedContacts.add(cCon.con); } } System.debug('These are the selected ...'); for(FinalBoost__c con: selectedContacts) { system.debug(con); } for (FinalBoost__c con: selectedContacts) { boostItems.add(new BoostOpp__c()); finalBoostId = con.Id; for(BoostOpp__c boostIteminList : boostItems) { boostIteminList.Opportunity__c = opportunityId; boostIteminList.FinalBoost__c = finalBoostId; } } insert boostItems; return oppPage; } // WrapperClass public class cBoost { public FinalBoost__c con {get; set;} public Boolean selected {get; set;} // Constructor public cBoost(FinalBoost__c c) { con = c; selected = false; } } }
A visualforcepage shows the table of FinalBoost records. I can select records and use them in the save methode. The BoostOpp__c object is a junction object. It is related to the opportunity and the FinalBoost Object.
In my loop, i want to create for each selected record one child record and assign the parent id (FinalBoost) to the masterDetail field. At the moment, it creates for each selection one record but allways with the same finalBoostId. Is there a simple solution for that ?
Cheers Sandra
Please find the solution below.
All Answers
Please find the solution below.
Now please mark my answer as best answer :P
could you help me again pls :( i need to get a user input in my wrapper class object and assign the value to the boost.userInputfield
What I understand is you want to bind the wrapper class variable which is(Custom Object -> FinalBoost__c field into visualforce tag inputfield)?, Please correct me if I am on wrong track,
okay for this I am providing u a visualforce code snippet it may help u :D
If this snippet dosen't helps you then please let me know I will be here with another solution for u :)
Thanks
SaketSharma
sharmasaket703@gmail.com
thanks for your quick response. Yes, that is what i want. It should work like the selected variable in the cBoost object. So i want to give the user the option to create a value for each selected cBoost object and use this input in my save methode
Thanks a lot !
Cheers Sandra
Is your problem is solved ? if not then let me know
Thanks
Greetings Sandra