Here i am not clear about the apex logic,
the flow is :
i have one child record Bundle__c and Product2 is parent, and i need to store multiple Product2 under Bundle__c (Product2 is located in related list under Bundle__c record)
To achieve this scenario i wrote visualforce page for multiselect product2 using checkbox and once user click on ADD Button then those all selected Products have to store under that related list of Bundle__c
here is my Page code :
<apex:page standardController="Product2" extensions="ProductSelectController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="TOP">
<apex:commandButton value="Add" action="{!AddProduct}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!productlist}" var="prlist">
<apex:column >
<apex:inputCheckbox value="{!selectedCheckBox}" />
</apex:column>
<apex:column headerValue="Product Name">
{!prList.Name}
</apex:column>
<apex:column headerValue="Description">
{!prList.Description}
</apex:column>
<apex:column headerValue="Price">
{!prList.Cost__c}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
Apex Class :
Public Class ProductSelectController{
public List<Product2> productlist{get;set;}
public boolean selectedCheckBox{get;set;}
//public Product2 pr{get;set;}
public Bundle__c bundle{get;set;}
public ProductSelectController(ApexPages.StandardController Controller){
productlist = [select Id, Name, Description, Cost__c from Product2];
bundle = new Bundle__c();
//pr = new Product2();
}
public Void AddProduct(){
for(Product2 p : productlist){
if(selectedCheckBox == True){
p.Bundle__c = bundle.Id;
system.debug('====P====='+p.Bundle__c);
}
}
}
}
Can anyone please help me !!