I am building CPQ Module for my client and I am done with Product and Bundle management Now, I am implementing Quote management and I am stuck for the following :
I am developing one visualforce page and apex class for the following requirement
I have a custom object named QBP__c
and in this object I need to store multiple Products in related list (only existing products) with entering Quantity of each products
To achieve this requirement I have created one field Product__c
(Lookup) because user will select product using this lookup field and after clicking on the save button it will
move to the related list of the QBP__c
object
Now, the question is how can I add multiple Products to this related list from selecting the product using lookup field ? And How can I add quantity to each product while saving from visualforce page ?
Let me show you my visualforce code :
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Add Product" action="{!addSection1}"/>
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:outputPanel >
<div>
<ul id="sortable">
<apex:variable value="" var="foo" rendered="{!IF(lstSections1 = True, true, false)}">
<apex:pageBlockSection title="Select Product">
<apex:actionRegion >
<apex:pageBlockTable value="{!QBP}" var="QBP">
<apex:column >
<apex:outputLabel >Select Product :</apex:outputLabel>
</apex:column>
<apex:column >
<apex:inputField value="{!QBP.Product__c}" >
<apex:actionSupport event="onchange" rerender="relatedInfo" action="{!retrieveproductInfo}" immediate="false"/>
</apex:inputField>
</apex:column>
<apex:column >
<apex:pageBlockSection id="relatedInfo">
<apex:outputText value="{!partNumber}" label="Part Number :"/>
<apex:outputText value="{!Description}" label="Description :"/>
</apex:pageBlockSection>
</apex:column>
</apex:pageBlockTable>
</apex:actionRegion>
</apex:pageBlockSection>
</apex:variable>
</ul>
</div>
</apex:outputPanel>
Apex Class :
public class AddQBPForQuoteController{
public Quote quote{get;set;}
public boolean lstSections1{get;set;}
public String partNumber{get;set;}
public String Description{get;set;}
public QBP__c QBP{get;set;}
public List<QBP__c> QBPList{get;set;}
public AddGroupForQuoteController(ApexPages.StandardController controller) {
lstSections1 = false;
grp = new Group__c();
QBP = new QBP__c();
QBPList = new List<QBP__c>();
this.quote = (Quote)controller.getRecord();
}
public void retrieveproductInfo() {
if(QBP.Product__c != Null){
this.partNumber = [SELECT Id, ProductCode FROM Product2 WHERE Id =: QBP.Product__c].ProductCode;
this.Description = [SELECT Id, Description FROM Product2 WHERE Id =: QBP.Product__c].Description;
}
}
public PageReference addSection1() {
lstSections1 = true;
QBP = new QBP__c();
QBPList.add(QBP);
return null;
}
public Pagereference Save(){
insert QBP;
for(integer i=0; i<QBPList.size(); i++){
this.partNumber = [SELECT Id, ProductCode FROM Product2 WHERE Id =: QBP.Product__c].ProductCode;
this.Description = [SELECT Id, Description FROM Product2 WHERE Id =: QBP.Product__c].Description;
}
upsert QBP;
return null;
}
public Pagereference Cancel(){
PageReference pg = new PageReference('/apex/AddQBPForQuote?id='+quote.Id);
pg.setRedirect(True);
return pg;
}
}