//This is where we have defined the Wrapper Class. public class OpportunityLineItemwrapper { // all the line record instance create public OpportunityLineItem prd{get; set;} public Boolean selected {get; set;} public OpportunityLineItemwrapper(OpportunityLineItem a) { prd = a; selected = false; } } // This is the Wrapper Name for the object Opportunity Line Items List<OpportunityLineItemwrapper> OppList = new List<OpportunityLineItemwrapper>(); List<OpportunityLineItem> selectedProducts = new List<OpportunityLineItem>();
//Defines a Map to store all items selected based on the ID from the ID from the URl. Map<Id,OpportunityLineItem> selectedProductsMap = new Map<Id,OpportunityLineItem>();
public Displayprodsinopprtunity(ApexPages.StandardController controller) {
}
public List<OpportunityLineItemwrapper> getProducts() { ID str = ApexPages.currentPage().getParameters().get('ID'); OppList.clear();
for(OpportunityLineItem a : [Select Id,Quantity, ListPrice,PricebookEntry.Product2Id,TotalPrice PricebookEntry.Name From OpportunityLineItem where Opportunity.id=:str]){
OpportunityLineItemwrapper opplineItem = new OpportunityLineItemwrapper(a); if (selectedProductsMap.get(a.Id) != null) opplineItem.selected = true;
public class Displayprods
{
//This is where we have defined the Wrapper Class.
public class OpportunityLineItemwrapper
{
// all the line record instance create
public OpportunityLineItem prd{get; set;}
public Boolean selected {get; set;}
public OpportunityLineItemwrapper(OpportunityLineItem a)
{
prd = a;
selected = false;
}
}
// This is the Wrapper Name for the object Opportunity Line Items
List<OpportunityLineItemwrapper> OppList = new List<OpportunityLineItemwrapper>();
List<OpportunityLineItem> selectedProducts = new List<OpportunityLineItem>();
//Defines a Map to store all items selected based on the ID from the ID from the URl.
Map<Id,OpportunityLineItem> selectedProductsMap = new Map<Id,OpportunityLineItem>();
public Displayprods(ApexPages.StandardController controller)
{
}
public List<OpportunityLineItemwrapper> getProducts()
{
ID str = ApexPages.currentPage().getParameters().get('Id');
OppList.clear();
for(OpportunityLineItem a : [Select Id,Quantity,
ListPrice,PricebookEntry.Product2Id,TotalPrice,
PricebookEntry.Name
From OpportunityLineItem
where Opportunity.id=:str])
{
OpportunityLineItemwrapper opplineItem = new OpportunityLineItemwrapper(a);
if (selectedProductsMap.get(a.Id) != null)
opplineItem.selected = true;
OppList.add(opplineItem);
}
return OppList;
}
public PageReference getSelected()
{
selectedProducts.clear();
for(OpportunityLineItemwrapper accwrapper : OppList)
if(accwrapper.selected == true)
{
selectedProducts.add(accwrapper.prd);
selectedProductsMap.put(accwrapper.prd.id, accwrapper.prd);
}
return null;
}
public List<OpportunityLineItem> GetSelectedProducts()
{
if(selectedProducts.size()>0)
return selectedProducts;
else
return null;
}
public void updateQuantity()
{
List<Id> SelectedIds = new List<Id>();
for(OpportunityLineItem litem: selectedProducts)
{
OpportunityLineItem updateQuantity = new OpportunityLineItem (Id=litem.Id,Quantity=22);
Update updateQuantity ;
}
}
}
1) i have scenario product name , price , quantity , total price and quantity = total ex:- 100 * 2 = 200 2) on that page create check box if you click the check box any select the record those select record they display on downside
i am try to first record dispaly if you check the check box they showing the record but i am unable to showing record
{
//This is where we have defined the Wrapper Class.
public class OpportunityLineItemwrapper
{
// all the line record instance create
public OpportunityLineItem prd{get; set;}
public Boolean selected {get; set;}
public OpportunityLineItemwrapper(OpportunityLineItem a)
{
prd = a;
selected = false;
}
}
// This is the Wrapper Name for the object Opportunity Line Items
List<OpportunityLineItemwrapper> OppList = new List<OpportunityLineItemwrapper>();
List<OpportunityLineItem> selectedProducts = new List<OpportunityLineItem>();
//Defines a Map to store all items selected based on the ID from the ID from the URl.
Map<Id,OpportunityLineItem> selectedProductsMap = new Map<Id,OpportunityLineItem>();
public Displayprodsinopprtunity(ApexPages.StandardController controller) {
}
public List<OpportunityLineItemwrapper> getProducts() {
ID str = ApexPages.currentPage().getParameters().get('ID');
OppList.clear();
for(OpportunityLineItem a : [Select Id,Quantity,
ListPrice,PricebookEntry.Product2Id,TotalPrice
PricebookEntry.Name From OpportunityLineItem
where Opportunity.id=:str]){
OpportunityLineItemwrapper opplineItem = new OpportunityLineItemwrapper(a);
if (selectedProductsMap.get(a.Id) != null)
opplineItem.selected = true;
OppList.add(opplineItem);
}
return OppList;
}
public PageReference getSelected() {
selectedProducts.clear();
for(OpportunityLineItemwrapper accwrapper : OppList)
if(accwrapper.selected == true) {
selectedProducts.add(accwrapper.prd);
selectedProductsMap.put(accwrapper.prd.id, accwrapper.prd);
}
return null;
}
public List<OpportunityLineItem> GetSelectedProducts() {
if(selectedProducts.size()>0)
return selectedProducts;
else
return null;
}
public void updateQuantity() {
List<Id> SelectedIds = new List<Id>();
for(OpportunityLineItem litem: selectedProducts) {
OpportunityLineItem updateQuantity = new OpportunityLineItem (Id=litem.Id,Quantity=22);
Update updateQuantity ;
}
}
}
<script>
function checkAll(cb)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf("checkedone")!=-1)
inputElem[i].checked = cb.checked;
}
}
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection Title="List of Available Products" id="ListProd">
<apex:dataTable value="{!Products}" var="a" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox >
<apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)" rerender="Selected_PBS"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!a.selected}" id="checkedone">
<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS"/>
</apex:inputCheckbox>
</apex:column>
<apex:column headervalue="Product Id" value="{!a.prd.Id}" />
<apex:column headervalue="Product Name" value="{!a.prd.PricebookEntry.Product2Id}" />
<apex:column headervalue="List Price" value="{!a.prd.ListPrice}" />
<apex:column headervalue="Quantity" value="{!a.prd.Quantity}" />
</apex:dataTable>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Selected Products" id="Selected_PBS">
<apex:dataTable value="{!SelectedProducts}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column headervalue="Product Id" value="{!s.Id}" />
<apex:column headervalue="Name" value="{!s.PricebookEntry.Name}" />
<apex:column headervalue="List Price" value="{!s.ListPrice}" />
<apex:column headervalue="Quantity" value="{!s.Quantity}" />
</apex:dataTable>
</apex:pageBlockSection>
<apex:commandButton action="{!updateQuantity}" ReRender="ListProd" Value="Update Quantity"/>
<apex:commandButton action="{!SendMail}" ReRender="ListProd" Value="Send Mail"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Display part is working properly for me.
1. I noticed here your using extension 'Displayprod' but class name was Displayprods.
2. sendEmail() method doesn't exist in Displayprods, so I commented out in VF page
3. public Displayprodsinopprtunity(ApexPages.StandardController controller) {
}
constructor name is wrong!! It should be :
public Displayprods(ApexPages.StandardController controller) {
}
price and quantity = total
ex:- 100 * 2 = 200
2) on that page create check box if you click the check box
any select the record those select record they display on downside
i am try to first record dispaly if you check the check box they showing the record
but i am unable to showing record