Working with Visual Force pages recently I've grown to like the benefits of defining inner class objects to store complex data structure as opposed to multidimensional maps. For example I can easily store aggregated data into an inner object like this simple example:
public CustomClass{
public class InnerObject{
public String var1
public Decimal var2
public InnerObject(Custom_Object__c record){
this.var1 = record.Custom1__c;
this.var2 = record.Custom2__c - record.Custom3__c;
}
}
public void testMethod(List<InnerObject> items){
for(InnerObject item : items){
System.debug('::TEST:: '+item.var1);
}
}
}
I've tested and found that I can use this in my trigger loop like so:
List<CustomClass.InnerObject> line_items = List<CustomClass.InnerObject>();
if(Trigger.isAfter && Trigger.isInsert){
for(Custom_Object__c c : (List<Custom_Object__c>) Trigger.new){
CustomClass.InnerObject line_item = new CustomClass.InnerObject(c);
System.debug('::LINE ITEM:: '+line_item);
line_items.add(line_item);
}
}
CustomClass.testMethod(line_items); // This doesn't work
Sweet! This seems promising thus far but then when I store this in a collection to send to a utility method (as shown above) I keep getting the following error:
Error: Method does not exist or incorrect signature: CustomClass.testMethod(List<CustomClass.InnerObject>)
Is this not possible? Not sure why I can get part of it to work but not the next part, wondering if I'm missing something. Any insight is appreciated, thanks!