So, i'm attempting to do some on the fly calculations in my controller and I've tried several different methods and am lost. I have 2 list's that i'm generating via dynamic SOQL queries one of which has pricing information the other having quote line level information from a custom object. The objects are not directly related, however I'm looking to join them on the product id which both objects contain (pbitm.Product2Id
and qlitm.SBQQ__Product__c
). Then I have a Decimal value that i want to use to calculate for each row using a field from the price object and a field from the quote line.
Here's what i have:
Public with sharing class CVF_DealSheet_Layout {
public SBQQ__Quote__c record {
get;
set;
}
//Begin Declaration of lookup objects
public SObject billTo {
get;
private set;
}
public SObject oppty {
get;
private set;
}
public SObject curfact {
get;
private set;
}
public list<SBQQ__QuoteLine__c> qlitm {
get;
set;
}
public list<SObject> pbitm {
get;
private set;
}
//Begin Declaration of public strings
public String objectTypeName {
get;
set;
}
public String objectName {
public get;
public set;
}
public Decimal currfactor {
public get;
public set;
}
public List<String> objectFields {get;set;}
public sObject sObjectToBind {get;set;}
public List<sObject> result {get;set;}
public SObject headSObject, headClone;
public void initialiseObjects() {
// Build a map of prefix to object name, eg. 001 -> Account.
Map<String, Schema.SObjectType> gd=Schema.getGlobalDescribe();
Map<String, String> keyPrefixMap=new Map<String, String> {}
;
for(String sObj: gd.keySet()) {
Schema.DescribeSObjectResult r=gd.get(sObj).getDescribe();
keyPrefixMap.put(r.getKeyPrefix(), r.getName());
}
// Determine the object name of the current record.
String objectID=ApexPages.currentPage().getParameters().get('id');
String billToID=ApexPages.currentPage().getParameters().get('Bill_To_Account_Number__c');
objectTypeName=keyPrefixMap.get(objectId.subString(0, 3));
String primaryObjectQueryString='SELECT Id, Name, Bill_To__c, SBQQ__Opportunity2__c, CurrencyIsoCode FROM ' + objectTypeName + ' WHERE Id = \'' + objectId + '\'';
headSObject=Database.query(primaryObjectQueryString);
// Bill To
String fetchbtid='' + headSObject.get('Bill_To__c');
String billToObjectQueryString='SELECT Id, Name, Region__c FROM Account WHERE Id = \'' + fetchbtid + '\'';
billTo=Database.query(BillToObjectQueryString); // execute the query
// Opportunity
String fetchoptid='' + headSObject.get('SBQQ__Opportunity2__c');
String opptyObjectQueryString='SELECT Id, Name, CloseDate FROM Opportunity WHERE Id = \'' + fetchoptid + '\'';
oppty=Database.query(opptyObjectQueryString); // execute the query
//Currency Info
String fetchcurdate=''+ oppty.get('CloseDate');
String strippeddate= fetchcurdate.left(10);
String fetchcurcode ='' + headSObject.get('CurrencyIsoCode');
String curfactquy = 'Select ConversionRate from DatedConversionRate where StartDate <'+ strippeddate +' AND NextStartDate >'+ strippeddate +' AND IsoCode = \'' + fetchcurcode + '\' LIMIT 1';
curfact=Database.query(curfactquy);
currfactor=Double.valueOf(curfact.get('ConversionRate'));
// Quote Lines
//Get Quote Lines
objectFields = new List<String>();
qlitm = new List<sObject>();
Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
String fetchqid='' + headSObject.get('Id');
String qlObjectQueryString='SELECT SBQQ__Product__c,fpartno__c, Model__c,SBQQ__ListPrice__c, SBQQ__PartnerDiscount__c, SBQQ__PartnerTotal__c, Disc_for_Approval__c, Target_Price__c, lookup_price_iUSD__c, Net_Customer_Total__c FROM SBQQ__QuoteLine__c WHERE SBQQ__Quote__c = \'' + fetchqid + '\'';
qlitm=Database.query(qlObjectQueryString); // execute the query
// Get PriceBook Info
String pbquerystring='SELECT Product2Id, UnitPrice FROM PricebookEntry WHERE Product2Id = \'' + fetchqid + '\' AND Pricebook2Id = \'01sU0000000PpLOIA0\'';
pbitm= [SELECT Product2Id, UnitPrice FROM PricebookEntry WHERE Pricebook2Id = '01sU0000000PpLOIA0'];
}
public CVF_DealSheet_Layout(ApexPages.StandardController controller) {
initialiseObjects();
}}
So what I'd like to do is combine qlitm and pbitm and then have 2 new columns for display in a VF page. One that calculates (qlitm.Net_Customer_Total__c* currfactor
) and one that calculates (qlitm.Net_Customer_Total__c* currfactor)/pbitm.UnitPrice
I'm just missing it syntactically here.