Products Products__c
Name | Label | Data Type | Sample Data | Sample Data 2 | Sample Data 3 |
---|---|---|---|---|---|
PDC | PDC__c | Text | ACA | ACG | TBC |
PDC Desc | PDC_Desc__c | Text | Tire Size | Rim / Wheel Disc Size | Type of Toolbox |
Value Desc | Value_Desc__c | Text | 255/70R 22.5 | 22.5×8.25 | None |
Prod Order | Prod_Order__c | Lookup | a1C2f000001jCyYEAU | a1C2f000001jCyYEAU | a1C2f000001jCyYEAU |
Product Groups Products_Groups__c
Name | Label | Type | Sample Data | Sample Data 2 | Sample Data 3 |
---|---|---|---|---|---|
Product Code | Product_Code__c | Text | ACA | ACG | TBC |
Product Group | Product_Group__c | Text | Tires / Wheels / Hubs and Drums | Tires / Wheels / Hubs and Drums | Tool Boxes |
Product Group Seq | Product_Group_Seq__c | Number | 2 | 2 | 5 |
Product Seq | Product_Seq__c | Number | 1 | 2 | 5 |
Desired VFP Results based on sample data. Sorted first by Product_Group_Seq__c then Product_Seq__c:
Tires / Wheels / Hubs and Drums | |
---|---|
Tire Size | 255/70R 22.5 |
Rim / Wheel Disc Size | 22.5×8.25 |
Tool Boxes | |
---|---|
Type of Toolbox | None |
Below is my standard controller.
I am trying to get this into a parent-child map format where I can display on visualforce page with the Product_Group__c
from Product_Groups__c
being a header value showing all Product_Code__c
and their child value Value_Desc__c
from Products__c
below in repeating format.
I am receiving attempt to de-reference null object
and I can see in debug it says AdjacentGroup|null
11:07:44:377 EXCEPTION_THROWN [23]|System.NullPointerException: Attempt to de-reference a null object
public with sharing class Productsv2Controller {
public String OrderId {get;set;}
public Map<String, Products_Groups__c> groupsMap {get;set;}
public Productsv2Controller() {
OrderId = ' ';
OrderId=System.currentPageReference().getParameters().get('id');
System.debug('...................OrderId=='+OrderId);
Id i= Id.valueOf(OrderId);
Map<String, Products_Groups__c> groupsMap = new Map<String, Products_Groups__c>();
for(Products_Groups__c og :[SELECT Id,Name, Product_Code__c,Product_Group_Seq__c,Product_Group__c,Product_Priority_Level__c,Product_Seq__c FROM Products_Groups__c]){
groupsMap.put(og.Product_Code__c, og);
}
for(Products__c o :[SELECT Id,PDC__c, PDC_Desc__c, Value_Desc__c from Products__c WHERE Prod_Order__c = :i]){
Products_Groups__c adjacentGroup = groupsMap.get(o.PDC__c);
system.debug('Group: '+adjacentGroup.Product_Group__c+' Code: '+adjacentGroup.Product_Code__c+' PDC: '+o.PDC__c+' Value: '+o.Value_Desc__c);
}
}
}
Best Answer
I would restructure this controller to use an inner class (sometimes called a wrapper class so your data model is easier to handle in the VF page
VF markup (based on VF doc) snippet
Some notes
action="{!doSomething}
on the page.