+ Start a Discussion
Ivan VrtacnikIvan Vrtacnik 

Advanced Apex Superbadge step 7 has a bug in the validation

While doing the challenge, I got stuck on step 7. I was reviewing the raw logs like many posts on this forum advised, and I saw this:
 
Map productMap = new Map([SELECT Id,Name FROM Product2]);
Map pricebookEntryMap = new Map([SELECT Id,Name FROM PricebookEntry]);

Map chartMap = new Map();
orderExtension ext = new orderExtension(new apexPages.standardController(new order()));
ext.orderItemList[0].Quantity = 1;
ext.orderItemList[0].UnitPrice = 1;
ext.orderItemList[1].Quantity = 2;
ext.omrderItemList[1].UnitPrice = 2;
for ( OrderItem oi : ext.orderItemList ){
String name;
if ( oi.Product2 != null && String.isNotBlank(oi.Product2.Name) ){
name = oi.Product2.Name;
}
else if ( oi.PricebookEntryId != null && String.isNotBlank(oi.PricebookEntry.Name) ){
name = oi.PricebookEntry.Name;
}
else if ( oi.Product2Id != null ){
name = productMap.get(oi.Product2Id).Name;
}
else if ( oi.PricebookEntryId != null ){
name = pricebookEntryMap.get(oi.PricebookEntryId).Name;
}
if ( String.isNotblank(name) && oi.Quantity != null && oi.UnitPrice != null ){
Decimal x = 0;
if ( chartMap.containsKey(oi.Product2.Name) ){
x = chartMap.get(oi.Product2.Name);
}
x += ( oi.Quantity * oi.UnitPrice );
chartMap.put(oi.Product2.Name,x);
}
}
ext.onFieldChange();

for ( chartHelper.chartData cd : ext.pieData ){
system.assert( cd.val == chartMap.get(cd.name), cd.name+': '+cd.val + '!='+ chartMap.get(cd.name) );
}

Now clearly, this snippet will only work for the edit case, and not for creating new OrderItems, as Product2 will be null in that case. I could of course fudge the code to get it to pass, but I don't want to do that. SalesForce support has already come back to me saying they cannot assit me. Does anyone know where to log this issue?
SandhyaSandhya (Salesforce Developers) 
Hi,

I would suggest you  reach trailhead@salesforce.com.

Best Regards,
Sandhya