You need to sign in to do that
Don't have an account?
Becky Miller 15
Apex Class --- New Code and System Log Debug not showing up in the Debug Log
Hello All,
For some reason piece of my code is not being read when creating a Quote. If the Quote Line Item has a Product Code = BMT-1003 I need an error message to appear. I have bolded where I am thinking I wrote the code wrong.
public with sharing class QuoteUtility {
public static void AddExtraVerbiage(list<Quote> lstQuotes){
map<Id, string> mapQuoteInstallReq = new map<Id, String>();
list<GPOTerms__c> lstGPOTerms = GPOTerms__c.getall().values();
map<String, Product_Installation_Requirement__c> mapInstallReq
= new Map<String, Product_Installation_Requirement__c>();
list<Product_Installation_Requirement__c> lstInstallReq
= [SELECT Name, Installation_Note__c
FROM Product_Installation_Requirement__c];
for(Product_Installation_Requirement__c p : lstInstallReq){
mapInstallReq.put(p.Name, p);
}
set<Id> setQuoteIds = new set<Id>();
for(Quote thisQuote : lstQuotes){
setQuoteIds.add(thisQuote.Id);
}
map<Id, QuoteLineItem> mapQLIs = new map<Id, QuoteLineItem>([SELECT Id, QuoteId,
PricebookEntry.Product2Id,
PricebookEntry.Product2.ProductCode,
PricebookEntry.Pricebook2.Name
FROM QuoteLineItem
WHERE QuoteId IN :setQuoteIds]);
for(Quote thisQuote : lstQuotes){
String strInstallReqs = '';
for(QuoteLineItem thisQI : mapQLIs.values()){
if (thisQI.QuoteId == thisQuote.Id){
//install req's
if(mapInstallReq.get(thisQI.PricebookEntry.Product2.ProductCode) != null){
if(!mapQuoteInstallReq.containsKey(thisQuote.Id)){
mapQuoteInstallReq.put(thisQuote.Id,
mapInstallReq.get(thisQI.PricebookEntry.Product2.ProductCode).Installation_Note__c + '\n');
} else {
mapQuoteInstallReq.put(thisQuote.Id,
mapQuoteInstallReq.get(thisQuote.Id)
+ mapInstallReq.get(thisQI.PricebookEntry.Product2.ProductCode).Installation_Note__c + '\n');
}
}
}
}
if(mapQuoteInstallReq.get(thisQuote.Id) != null){
thisQuote.Product_Specific_Instructions__c
= mapQuoteInstallReq.get(thisQuote.Id);
}
//GPO Terms
for(GPOTerms__c thisGPOTerm : lstGPOTerms) {
if(thisQuote.GPO_Affiliation__c != null) {
if(thisQuote.GPO_Affiliation__c.contains(thisGPOTerm.Name)) {
thisQuote.Customer_Tier__c = thisGPOTerm.Terms__c;
}
}
}
}
}
public static void ValidateLineItems(list<Quote> lstQuotes){
set<Id> setQuoteIds = new set<Id>();
map<Id, boolean> mapQuoteIsCapital = new map<Id, boolean>();
map<Id, integer> mapQuoteCapitalCount = new map<Id, integer>();
map<Id, boolean> mapQuoteHasZeroDollar = new map<Id, boolean>();
map<Id, decimal> mapQuoteZeroDollarTotal = new map<Id, decimal>();
map<Id, decimal> mapQuoteTradeInValue = new map<Id, decimal>();
map<Id, String> mapQuoteBIOMed = new map<Id, String>();
map<Id, String> mapQuoteErrorList = new map<Id, String>();
map<Id, String> mapQuoteApprovalLevel = new map<Id, String>();
map<Id, map<string, decimal>> mapQuoteZeroDollarExceptions
= new map<Id, map<string,decimal>>();
map<Id, map<string, decimal>> mapQuoteExceptionsUsed
= new map<Id, map<string,decimal>>();
for(Quote thisQuote : lstQuotes){
setQuoteIds.add(thisQuote.Id);
thisQuote.Status_Message__c = null;
mapQuoteCapitalCount.put(thisQuote.Id, 0);
mapQuoteTradeInValue.put(thisQuote.Id, 0);
mapQuoteZeroDollarExceptions.put(thisQuote.Id, new map<string, decimal>());
mapQuoteExceptionsUsed.put(thisQuote.Id, new map<string, decimal>());
}
map<Id, QuoteLineItem> mapQLIs = new map<Id, QuoteLineItem>([SELECT Id, QuoteId,
PricebookEntry.Product2Id,
PricebookEntry.Product2.ProductCode,
PricebookEntry.Pricebook2.IsStandard,
PricebookEntry.Product_Exceptions__c,
PricebookEntry.UseStandardPrice,
PricebookEntry.UnitPrice,
PricebookEntry.Pricebook2.Id,
PricebookEntry.Pricebook2Id,
PricebookEntry.Minimum_Price__c,
PricebookEntry.RD_Minimum_Price__c,
PricebookEntry.Product2.Family,
PricebookEntry.Product2.Installed_Product__c,
PricebookEntry.Pricebook2.Name,
UnitPrice,
Quantity
FROM QuoteLineItem
WHERE QuoteId IN :setQuoteIds
ORDER BY PricebookEntry.UnitPrice DESC]);
for(QuoteLineItem thisQL : mapQLIs.values()){
system.debug(logginglevel.ERROR, 'thisQL: ' + thisQL);
if(thisQL.PricebookEntry.Product2.Family != null){
//if(thisQL.PricebookEntry.Product2.Family.Contains('Reprocessor')
// || thisQL.PricebookEntry.Product2.Installed_Product__c == true){
mapQuoteIsCapital.put(thisQL.QuoteId, true);
if(thisQL.PricebookEntry.Product_Exceptions__c != null){
for(string thisExceptionLevel : thisQL.PricebookEntry.Product_Exceptions__c.split('\r\n')){
if(!(mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).containsKey(thisExceptionLevel.split('\\|')[0]))){
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).put(thisExceptionLevel.split('\\|')[0], decimal.valueof(thisExceptionLevel.split('\\|')[1])*thisQL.Quantity);
} else {
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).put(thisExceptionLevel.split('\\|')[0],
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).get(thisExceptionLevel.split('\\|')[0])
+ decimal.valueof(thisExceptionLevel.split('\\|')[1])*thisQL.Quantity);
}
}
}
system.debug(logginglevel.ERROR, 'ZeroDollarExceptions: ' + mapQuoteZeroDollarExceptions);
//}
}
if(thisQL.PricebookEntry.Product2.ProductCode == 'Upgrade Discount'){
mapQuoteTradeInvalue.put(thisQL.QuoteId,
mapQuoteTradeInvalue.get(thisQL.QuoteId) + thisQL.UnitPrice);
}
if(thisQL.PricebookEntry.Product2.ProductCode == 'BMT-1003'){
mapQuoteBIOMed.put(thisQL.QuoteId,
mapQuoteBIOMed.get(thisQL.QuoteId) + thisQL.UnitPrice);
}
}
system.debug(logginglevel.ERROR, 'Starting Second Loop');
for(QuoteLineItem thisQL : mapQLIs.values()){
if(thisQL.UnitPrice == 0){ //for each zero dollar line item
boolean isValidException = false;
mapQuoteHasZeroDollar.put(thisQL.QuoteId, true);
for(string thisException : mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).keySet()){ //go through all of the exceptions
system.debug(logginglevel.ERROR, 'Exceptions for this Quote: ' + mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).keySet());
system.debug(logginglevel.ERROR, 'This Exception: ' + thisException);
if(thisException.contains(thisQL.PricebookEntry.Product2.ProductCode)){
system.debug(logginglevel.ERROR, 'Exception List Contains this part');
if(!(mapQuoteExceptionsUsed.get(thisQL.QuoteId).containsKey(thisException))){ //if there isn't an exc used for this
mapQuoteExceptionsUsed.get(thisQL.QuoteId).put(thisException, thisQL.Quantity); //put one
} else {
system.debug(logginglevel.ERROR, 'Exception List doesnt contain this part');
mapQuoteExceptionsUsed.get(thisQL.QuoteId).put(thisException, //otherwise get it and add to it
mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException) + thisQL.Quantity);
}
if(mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException) != null){
system.debug(logginglevel.ERROR, 'Used Exceptions: ' + mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException));
system.debug(logginglevel.ERROR, 'Available Exceptions: ' + mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).get(thisException));
if(mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException) <= //ths is coming back as even
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).get(thisException)){
isValidException = true;
break;
} else {
isValidException = false;
}
}
System.debug(logginglevel.ERROR,'BMT-1003 Product');
system.debug(logginglevel.ERROR, 'thisQL: ' + thisQL);
if(thisQL.Product_Code__c == ('BMT-1003')
&& (mapQuoteApprovalLevel.get(thisQL.QuoteId) == null
|| mapQuoteApprovalLevel.get(thisQL.QuoteId) == 'Director'))
{
if(!(mapQuoteErrorList.containsKey(thisQL.QuoteId))){
mapQuoteErrorList.put(thisQL.QuoteId, 'The Bio-Med Training quoted for ' +
thisQL.PricebookEntry.Product2.ProductCode
+ 'needs to have Service Director and DOS Approval.' + '</br>');
} else
{
mapQuoteErrorList.put(thisQL.QuoteId, mapQuoteErrorList.get(thisQL.QuoteId)
+ 'The Bio-Med Training quoted for' +
thisQL.PricebookEntry.Product2.ProductCode
+ ' needs to have Service Director and DOS Approval.' + '</br>');
}
}
For some reason piece of my code is not being read when creating a Quote. If the Quote Line Item has a Product Code = BMT-1003 I need an error message to appear. I have bolded where I am thinking I wrote the code wrong.
public with sharing class QuoteUtility {
public static void AddExtraVerbiage(list<Quote> lstQuotes){
map<Id, string> mapQuoteInstallReq = new map<Id, String>();
list<GPOTerms__c> lstGPOTerms = GPOTerms__c.getall().values();
map<String, Product_Installation_Requirement__c> mapInstallReq
= new Map<String, Product_Installation_Requirement__c>();
list<Product_Installation_Requirement__c> lstInstallReq
= [SELECT Name, Installation_Note__c
FROM Product_Installation_Requirement__c];
for(Product_Installation_Requirement__c p : lstInstallReq){
mapInstallReq.put(p.Name, p);
}
set<Id> setQuoteIds = new set<Id>();
for(Quote thisQuote : lstQuotes){
setQuoteIds.add(thisQuote.Id);
}
map<Id, QuoteLineItem> mapQLIs = new map<Id, QuoteLineItem>([SELECT Id, QuoteId,
PricebookEntry.Product2Id,
PricebookEntry.Product2.ProductCode,
PricebookEntry.Pricebook2.Name
FROM QuoteLineItem
WHERE QuoteId IN :setQuoteIds]);
for(Quote thisQuote : lstQuotes){
String strInstallReqs = '';
for(QuoteLineItem thisQI : mapQLIs.values()){
if (thisQI.QuoteId == thisQuote.Id){
//install req's
if(mapInstallReq.get(thisQI.PricebookEntry.Product2.ProductCode) != null){
if(!mapQuoteInstallReq.containsKey(thisQuote.Id)){
mapQuoteInstallReq.put(thisQuote.Id,
mapInstallReq.get(thisQI.PricebookEntry.Product2.ProductCode).Installation_Note__c + '\n');
} else {
mapQuoteInstallReq.put(thisQuote.Id,
mapQuoteInstallReq.get(thisQuote.Id)
+ mapInstallReq.get(thisQI.PricebookEntry.Product2.ProductCode).Installation_Note__c + '\n');
}
}
}
}
if(mapQuoteInstallReq.get(thisQuote.Id) != null){
thisQuote.Product_Specific_Instructions__c
= mapQuoteInstallReq.get(thisQuote.Id);
}
//GPO Terms
for(GPOTerms__c thisGPOTerm : lstGPOTerms) {
if(thisQuote.GPO_Affiliation__c != null) {
if(thisQuote.GPO_Affiliation__c.contains(thisGPOTerm.Name)) {
thisQuote.Customer_Tier__c = thisGPOTerm.Terms__c;
}
}
}
}
}
public static void ValidateLineItems(list<Quote> lstQuotes){
set<Id> setQuoteIds = new set<Id>();
map<Id, boolean> mapQuoteIsCapital = new map<Id, boolean>();
map<Id, integer> mapQuoteCapitalCount = new map<Id, integer>();
map<Id, boolean> mapQuoteHasZeroDollar = new map<Id, boolean>();
map<Id, decimal> mapQuoteZeroDollarTotal = new map<Id, decimal>();
map<Id, decimal> mapQuoteTradeInValue = new map<Id, decimal>();
map<Id, String> mapQuoteBIOMed = new map<Id, String>();
map<Id, String> mapQuoteErrorList = new map<Id, String>();
map<Id, String> mapQuoteApprovalLevel = new map<Id, String>();
map<Id, map<string, decimal>> mapQuoteZeroDollarExceptions
= new map<Id, map<string,decimal>>();
map<Id, map<string, decimal>> mapQuoteExceptionsUsed
= new map<Id, map<string,decimal>>();
for(Quote thisQuote : lstQuotes){
setQuoteIds.add(thisQuote.Id);
thisQuote.Status_Message__c = null;
mapQuoteCapitalCount.put(thisQuote.Id, 0);
mapQuoteTradeInValue.put(thisQuote.Id, 0);
mapQuoteZeroDollarExceptions.put(thisQuote.Id, new map<string, decimal>());
mapQuoteExceptionsUsed.put(thisQuote.Id, new map<string, decimal>());
}
map<Id, QuoteLineItem> mapQLIs = new map<Id, QuoteLineItem>([SELECT Id, QuoteId,
PricebookEntry.Product2Id,
PricebookEntry.Product2.ProductCode,
PricebookEntry.Pricebook2.IsStandard,
PricebookEntry.Product_Exceptions__c,
PricebookEntry.UseStandardPrice,
PricebookEntry.UnitPrice,
PricebookEntry.Pricebook2.Id,
PricebookEntry.Pricebook2Id,
PricebookEntry.Minimum_Price__c,
PricebookEntry.RD_Minimum_Price__c,
PricebookEntry.Product2.Family,
PricebookEntry.Product2.Installed_Product__c,
PricebookEntry.Pricebook2.Name,
UnitPrice,
Quantity
FROM QuoteLineItem
WHERE QuoteId IN :setQuoteIds
ORDER BY PricebookEntry.UnitPrice DESC]);
for(QuoteLineItem thisQL : mapQLIs.values()){
system.debug(logginglevel.ERROR, 'thisQL: ' + thisQL);
if(thisQL.PricebookEntry.Product2.Family != null){
//if(thisQL.PricebookEntry.Product2.Family.Contains('Reprocessor')
// || thisQL.PricebookEntry.Product2.Installed_Product__c == true){
mapQuoteIsCapital.put(thisQL.QuoteId, true);
if(thisQL.PricebookEntry.Product_Exceptions__c != null){
for(string thisExceptionLevel : thisQL.PricebookEntry.Product_Exceptions__c.split('\r\n')){
if(!(mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).containsKey(thisExceptionLevel.split('\\|')[0]))){
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).put(thisExceptionLevel.split('\\|')[0], decimal.valueof(thisExceptionLevel.split('\\|')[1])*thisQL.Quantity);
} else {
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).put(thisExceptionLevel.split('\\|')[0],
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).get(thisExceptionLevel.split('\\|')[0])
+ decimal.valueof(thisExceptionLevel.split('\\|')[1])*thisQL.Quantity);
}
}
}
system.debug(logginglevel.ERROR, 'ZeroDollarExceptions: ' + mapQuoteZeroDollarExceptions);
//}
}
if(thisQL.PricebookEntry.Product2.ProductCode == 'Upgrade Discount'){
mapQuoteTradeInvalue.put(thisQL.QuoteId,
mapQuoteTradeInvalue.get(thisQL.QuoteId) + thisQL.UnitPrice);
}
if(thisQL.PricebookEntry.Product2.ProductCode == 'BMT-1003'){
mapQuoteBIOMed.put(thisQL.QuoteId,
mapQuoteBIOMed.get(thisQL.QuoteId) + thisQL.UnitPrice);
}
}
system.debug(logginglevel.ERROR, 'Starting Second Loop');
for(QuoteLineItem thisQL : mapQLIs.values()){
if(thisQL.UnitPrice == 0){ //for each zero dollar line item
boolean isValidException = false;
mapQuoteHasZeroDollar.put(thisQL.QuoteId, true);
for(string thisException : mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).keySet()){ //go through all of the exceptions
system.debug(logginglevel.ERROR, 'Exceptions for this Quote: ' + mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).keySet());
system.debug(logginglevel.ERROR, 'This Exception: ' + thisException);
if(thisException.contains(thisQL.PricebookEntry.Product2.ProductCode)){
system.debug(logginglevel.ERROR, 'Exception List Contains this part');
if(!(mapQuoteExceptionsUsed.get(thisQL.QuoteId).containsKey(thisException))){ //if there isn't an exc used for this
mapQuoteExceptionsUsed.get(thisQL.QuoteId).put(thisException, thisQL.Quantity); //put one
} else {
system.debug(logginglevel.ERROR, 'Exception List doesnt contain this part');
mapQuoteExceptionsUsed.get(thisQL.QuoteId).put(thisException, //otherwise get it and add to it
mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException) + thisQL.Quantity);
}
if(mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException) != null){
system.debug(logginglevel.ERROR, 'Used Exceptions: ' + mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException));
system.debug(logginglevel.ERROR, 'Available Exceptions: ' + mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).get(thisException));
if(mapQuoteExceptionsUsed.get(thisQL.QuoteId).get(thisException) <= //ths is coming back as even
mapQuoteZeroDollarExceptions.get(thisQL.QuoteId).get(thisException)){
isValidException = true;
break;
} else {
isValidException = false;
}
}
System.debug(logginglevel.ERROR,'BMT-1003 Product');
system.debug(logginglevel.ERROR, 'thisQL: ' + thisQL);
if(thisQL.Product_Code__c == ('BMT-1003')
&& (mapQuoteApprovalLevel.get(thisQL.QuoteId) == null
|| mapQuoteApprovalLevel.get(thisQL.QuoteId) == 'Director'))
{
if(!(mapQuoteErrorList.containsKey(thisQL.QuoteId))){
mapQuoteErrorList.put(thisQL.QuoteId, 'The Bio-Med Training quoted for ' +
thisQL.PricebookEntry.Product2.ProductCode
+ 'needs to have Service Director and DOS Approval.' + '</br>');
} else
{
mapQuoteErrorList.put(thisQL.QuoteId, mapQuoteErrorList.get(thisQL.QuoteId)
+ 'The Bio-Med Training quoted for' +
thisQL.PricebookEntry.Product2.ProductCode
+ ' needs to have Service Director and DOS Approval.' + '</br>');
}
}
It looks like your code is looking for the "Product_Code__c" field on the Quote Line Item, but the rest of your code is looking for "PricebookEntry.Product2.ProductCode"
Try either adding Product_Code__c to your QuoteLineItem query and printing it out in a System.debug to see what value it holds, or fixing the code below use the PricebookEntry.Product2.ProductCode field.
Also, when you post code on the forums, please use the code formatting button (< >). It helps with code readability and allows responders to copy and paste if necessary. Thanks!