You need to sign in to do that
Don't have an account?
Controller Extension for a Related List
I am fairly new to the Apex crowd but I have created two objects that have Master Detail Relationship. The Commission Rec object is the master and Order Entry as the child. I am creating a VF Page to render as PDF to be used as a report. I can use the Standard Controller for the information I need to display from the Commission Rec and the information from the Order Entry is all contained in the Related List. The problem is that the Order Entry contains a Sales Rep field that I need to group the results by and then subtotal both the Total and Commission Paid fields. My thought has been that I could just write a controller extension for the Commission Rec object and use the AggregateResults and Group By funtions but I am having a hard writing the extention. I have tried to leverage the various examples I have seen on the web of how to write the new list but I am really having a hard time finding an example that is as simple as what I need. I don't have to filter any data and I am pulling records that are already defined in a one-to-many relationship. Does anyone have an example of code that will take a standard related list and group and subtotal the results?
thank you,
Bryan
pass the Commission Rec object id to the controller extension and do furthur logic there.
Here is sample code.
public class VFpageExtn{
public commisionobject cm {get;set;}
public VFpageExtn(ApexPages.StandardController controller){
cm=(commisionobject)controller.getRecord();
cm = [select id Name, your Oject filed ,( fields from your child object) from commisionobject where id =: cm.id];
odrderentryAggregateResults(cm);
}
public void odrderentryAggregateResults(commisionobject cmo){
Map<String, decimal> SalesRepToTotal = new Map<String, decimal>();
for(AggregateResult ar :[select sum(Total) tot, sum(CommissionPaid) cp, salesRep from childobject where parentobjectid =:cmo.id group by salesRep])
{
SalesRepToTotal.put((String)ar.get('salesRep'),(decimal)(ar.get('tot')+ar.get('cp'));
}
}
}