You need to sign in to do that
Don't have an account?

Variable does not exist: wrapProducts
I am trying to add selected products from the list
global class ProductSearchPopupController {
public String query {get; set;}
public List<PricebookEntry__c> products {get; set;}
public List<wrapProduct> wrapProductList {get; set;}
public List<PricebookEntry__c> selectedProduct{get;set;}
public List<QuoteLineitem__c> quoteLineList{get;set;}
public List<wrapProduct> selectedWrapperList{get;set;}
public Boolean normalList{get;set;}
public Boolean selectedList{get;set;}
public Boolean block{get;set;}
public Boolean block1{get;set;}
public Boolean block2{get;set;}
public String SalesPrice {get; set;}
public integer Discount {get; set;}
public String Quantity {get; set;}
public String ServiceDate {get; set;}
Id recordId;
public ProductSearchPopupController(ApexPages.StandardController controller){
recordId = controller.getId();
SalesPrice='';
Discount=0;
Quantity='';
ServiceDate='';
system.debug('recordId '+recordId);
wrapProductList = new List<wrapProduct>();
selectedWrapperList = new List<wrapProduct>();
normalList = true;
selectedList = false;
block = true;
block1 = false;
block2 = false;
}
public PageReference runQuery(){
if(Test.isRunningTest()){
query='Test';
}
system.debug('this query '+query);
if(query == null || query == ''){
system.debug('query '+query);
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter the product to be searched'));
return null;
}
List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
system.debug('searchResults '+searchResults[0].size());
System.debug('searchResults result ' + searchResults[0]);
System.debug('oth result ' + SearchResults[0]);
if(searchResults[0]!=null){
for(PricebookEntry__c a: searchResults[0]) {
// As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
wrapProductList.add(new wrapProduct(a));
block = true; block1 = true; block2 = false;
}
}
return null;
}
public void processSelected() {
wrapProducts = new List<Product2__c>();
for(wrapProducts wrapProductObj : wrapAccountList) {
if(wrapProductObj.selected == true) {
selectedProducts.add(wrapProductObj.acc);
}
}
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
public class wrapProducts {
public Product2__c acc {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false
public wrapProducts(Product2__c a) {
acc = a;
selected = false;
}
}
public PageReference ProceedWithSelectedToNextPage(){
selectedWrapperList = new List<wrapProduct>();
normalList = false;
selectedList = true;
for(wrapProduct selectedWrapObj: wrapProductList){
system.debug('selectedWrapObj.selected ---------'+selectedWrapObj.selected);
if(selectedWrapObj.selected == true)
selectedWrapperList.add(selectedWrapObj);
}
system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
pageRef.setRedirect(false);
return pageRef;
}
public void SelectProduct() {
selectedProduct = new List<PricebookEntry__c>();
for(wrapProduct wrapProductObj : wrapProductList) {
if(wrapProductObj.selected == true) {
selectedProduct.add(wrapProductObj.acc);
block = false; block1 = false; block2 = true;
}
}
}
public void GoBack() {
block = true;
block1 = true;
block2 = false;
}
global class wrapProduct {
public PricebookEntry__c acc {get;set;}
public Boolean selected {get;set;}
public wrapProduct(PricebookEntry__c p) {
this.acc = p;
this.selected = false;
}
}
public pagereference saveproduct(){
List<QuoteLineitem__c> quoteLineList = new List<QuoteLineitem__c>();
if(Test.isRunningTest()){
insertTestData();
}
if(!selectedProduct.isEmpty()){
for(PricebookEntry__c sp:selectedProduct){
system.debug('sp '+sp);
QuoteLineitem__c qli = new QuoteLineitem__c();
qli.QuotesId__c = recordId;
qli.ListPrice__c = sp.UnitPrice__c;
qli.UnitPrice__c = sp.UnitPrice__c;
qli.Product2Id__c = sp.Product2Id__c;
if(Discount!=0 || Discount!=null){
qli.Discount__c = Discount;
}
quoteLineList.add(qli);
}
if(quoteLineList.size()>0){
insert quoteLineList;
PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
pageRef.setRedirect(true);
return pageRef;
}
}
return null;
}
public void insertTestData(){
Product2__c testProduct = new Product2__c();
testProduct.Name='Test product';
insert testProduct;
PricebookEntry__c testpbe = new PricebookEntry__c();
testpbe.Name='Test PriceBookEntry';
testpbe.UnitPrice__c =123;
testpbe.Product2Id__c=testProduct.Id;
insert testpbe;
selectedProduct.add(testpbe);
}
}

global class ProductSearchPopupController {
public String query {get; set;}
public List<PricebookEntry__c> products {get; set;}
public List<wrapProduct> wrapProductList {get; set;}
public List<PricebookEntry__c> selectedProduct{get;set;}
public List<QuoteLineitem__c> quoteLineList{get;set;}
public List<wrapProduct> selectedWrapperList{get;set;}
public Boolean normalList{get;set;}
public Boolean selectedList{get;set;}
public Boolean block{get;set;}
public Boolean block1{get;set;}
public Boolean block2{get;set;}
public String SalesPrice {get; set;}
public integer Discount {get; set;}
public String Quantity {get; set;}
public String ServiceDate {get; set;}
Id recordId;
public ProductSearchPopupController(ApexPages.StandardController controller){
recordId = controller.getId();
SalesPrice='';
Discount=0;
Quantity='';
ServiceDate='';
system.debug('recordId '+recordId);
wrapProductList = new List<wrapProduct>();
selectedWrapperList = new List<wrapProduct>();
normalList = true;
selectedList = false;
block = true;
block1 = false;
block2 = false;
}
public PageReference runQuery(){
if(Test.isRunningTest()){
query='Test';
}
system.debug('this query '+query);
if(query == null || query == ''){
system.debug('query '+query);
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Please enter the product to be searched'));
return null;
}
List<List<PricebookEntry__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING PricebookEntry__c (id, Name, ProductCode__c, Product2Id__r.Product_Description__c,UnitPrice__c, UseStandardPrice__c)];
system.debug('searchResults '+searchResults[0].size());
System.debug('searchResults result ' + searchResults[0]);
System.debug('oth result ' + SearchResults[0]);
if(searchResults[0]!=null){
for(PricebookEntry__c a: searchResults[0]) {
// As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
wrapProductList.add(new wrapProduct(a));
block = true; block1 = true; block2 = false;
}
}
return null;
}
public void processSelected() {
wrapProducts = new List<Product2__c>();
for(wrapProducts wrapProductObj : wrapAccountList) {
if(wrapProductObj.selected == true) {
selectedProducts.add(wrapProductObj.acc);
}
}
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
public class wrapProducts {
public Product2__c acc {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false
public wrapProducts(Product2__c a) {
acc = a;
selected = false;
}
}
public PageReference ProceedWithSelectedToNextPage(){
selectedWrapperList = new List<wrapProduct>();
normalList = false;
selectedList = true;
for(wrapProduct selectedWrapObj: wrapProductList){
system.debug('selectedWrapObj.selected ---------'+selectedWrapObj.selected);
if(selectedWrapObj.selected == true)
selectedWrapperList.add(selectedWrapObj);
}
system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
PageReference pageRef = new PageReference('/apex/AccountOpportunityTwoPage');
pageRef.setRedirect(false);
return pageRef;
}
public void SelectProduct() {
selectedProduct = new List<PricebookEntry__c>();
for(wrapProduct wrapProductObj : wrapProductList) {
if(wrapProductObj.selected == true) {
selectedProduct.add(wrapProductObj.acc);
block = false; block1 = false; block2 = true;
}
}
}
public void GoBack() {
block = true;
block1 = true;
block2 = false;
}
global class wrapProduct {
public PricebookEntry__c acc {get;set;}
public Boolean selected {get;set;}
public wrapProduct(PricebookEntry__c p) {
this.acc = p;
this.selected = false;
}
}
public pagereference saveproduct(){
List<QuoteLineitem__c> quoteLineList = new List<QuoteLineitem__c>();
if(Test.isRunningTest()){
insertTestData();
}
if(!selectedProduct.isEmpty()){
for(PricebookEntry__c sp:selectedProduct){
system.debug('sp '+sp);
QuoteLineitem__c qli = new QuoteLineitem__c();
qli.QuotesId__c = recordId;
qli.ListPrice__c = sp.UnitPrice__c;
qli.UnitPrice__c = sp.UnitPrice__c;
qli.Product2Id__c = sp.Product2Id__c;
if(Discount!=0 || Discount!=null){
qli.Discount__c = Discount;
}
quoteLineList.add(qli);
}
if(quoteLineList.size()>0){
insert quoteLineList;
PageReference pageRef = new PageReference('https://proseraa.lightning.force.com/lightning/r/Quotes__c/'+recordId+'/view');
pageRef.setRedirect(true);
return pageRef;
}
}
return null;
}
public void insertTestData(){
Product2__c testProduct = new Product2__c();
testProduct.Name='Test product';
insert testProduct;
PricebookEntry__c testpbe = new PricebookEntry__c();
testpbe.Name='Test PriceBookEntry';
testpbe.UnitPrice__c =123;
testpbe.Product2Id__c=testProduct.Id;
insert testpbe;
selectedProduct.add(testpbe);
}
}
Those variables will need to be declared before being used.