You need to sign in to do that
Don't have an account?
Jayaramu T 9
public Pricebook2 theBook {get;set;}
public List<Authorized_Product__c> authorizedProductObjList =[SELECT Active__c,Distribution_Type__c,Id,Name,Product_Category__c,Product_Collection__c,Price_Book__c,
Product_Family__c,Reseller__c,Standard_Discount__c,Demo_Unit_Discount__c ,Parts_Discount__c,Material_Discount__c
FROM Authorized_Product__c WHERE Reseller__c = :theOpp.RapidForm_Reseller__c AND Active__c = true];
for(Authorized_Product__c authp : authorizedProductObjList){
if(PPP && authp.Product_Family__c.contains('Printers') && authp.Price_Book__c!=null){
theBook = [select Id, Name from Pricebook2 where ID = :authp.Price_book__c];
forcePricebookSelection=false;
}
}
}
I need to avoid SOQL query inside for loop but it is using for loop reference variable any suggetions please to avoid soql in loop below is the code
public Pricebook2 theBook {get;set;}
public List<Authorized_Product__c> authorizedProductObjList =[SELECT Active__c,Distribution_Type__c,Id,Name,Product_Category__c,Product_Collection__c,Price_Book__c,
Product_Family__c,Reseller__c,Standard_Discount__c,Demo_Unit_Discount__c ,Parts_Discount__c,Material_Discount__c
FROM Authorized_Product__c WHERE Reseller__c = :theOpp.RapidForm_Reseller__c AND Active__c = true];
for(Authorized_Product__c authp : authorizedProductObjList){
if(PPP && authp.Product_Family__c.contains('Printers') && authp.Price_Book__c!=null){
theBook = [select Id, Name from Pricebook2 where ID = :authp.Price_book__c];
forcePricebookSelection=false;
}
}
}
Please find the below code as per your requirement :
public Pricebook2 theBook {get;set;}
public List<Authorized_Product__c> authorizedProductObjList =[SELECT Active__c,Distribution_Type__c,Id,Name,Product_Category__c,Product_Collection__c,Price_Book__c,
Product_Family__c,Reseller__c,Standard_Discount__c,Demo_Unit_Discount__c ,Parts_Discount__c,Material_Discount__c
FROM Authorized_Product__c WHERE Reseller__c = :theOpp.RapidForm_Reseller__c AND Active__c = true];
theBook = [select Id, Name from Pricebook2];
for(Authorized_Product__c authp : authorizedProductObjList){
if(PPP && authp.Product_Family__c.contains('Printers') && authp.Price_Book__c!=null){
if(theBook.id==authp.Price_book__c){
forcePricebookSelection=false;
}
}
}
}
Thanks
Salesforce Developer Group
<pre>
public Pricebook2 theBook { get; set; }
public List<Authorized_Product__c> authorizedProductObjList =
( [ SELECT Id, Name, Active__c, Distribution_Type__c, Product_Category__c,
Product_Collection__c,
Product_Family__c, Reseller__c, Standard_Discount__c,
Demo_Unit_Discount__c, Parts_Discount__c, Material_Discount__c,
Price_Book__c, Price_Book__r.Id, Price_Book__r.Name
FROM Authorized_Product__c
WHERE ( Reseller__c = :theOpp.RapidForm_Reseller__c
AND Active__c = true
)
]
);
for ( Authorized_Product__c authp : authorizedProductObjList )
{
if ( PPP
&& authp.Product_Family__c.contains( 'Printers' )
&& authp.Price_Book__c != null
)
{
theBook = authp.Price_book__r;
forcePricebookSelection = false;
}
}
</pre>