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 {

//Begin Declaration of lookup objects
public SObject billTo {
    private set;
public SObject oppty {
    private set;
public SObject curfact {
    private set;

public list<SBQQ__QuoteLine__c> qlitm {
public list<SObject> pbitm {
    private set;
//Begin Declaration of public strings
public String objectTypeName {
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 + '\'';

    // 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';

    // 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) {



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.

1 Answer 1


How about using wrapper class for this? The data that you are getting is from two different objects and you want to perform calculation using both.Declare a wrapper class similar to the one below:

public class LineItemWrapper{

    Pricing_Information__c objPricingInfo;
    Quote_Line_Item__c objQuoteLineItem;
    Decimal value 1;// storing calculation 1 value
    decimal value 2;//storing calculation 2 value

now in your method of filling values, create wrapper class objects and populate them with the proper data , put them in a list and display that in a table

  • Request you to mark this as the correct answer if it helps you in solving your problem :)
    – Abhijeet
    Commented Jul 28, 2016 at 16:55
  • Ok, this makes a ton more sense to me now. Last question, what is the syntax for referencing the class?
    – Jsjjharp
    Commented Jul 28, 2016 at 17:27
  • Referencing the wrapper class right?? It's similar to instantiating an object.So say ur class name is same as above( line item wrapper) do it like LineItemWrapper obj = new LineItemWrapper()
    – Abhijeet
    Commented Jul 28, 2016 at 18:03
  • Request you to mark this answer as the solution if it works fr you, in order to help other guys :)
    – Abhijeet
    Commented Jul 28, 2016 at 18:14
  • Yes but how do i feed it the other two objects assuming they are called qlitm and pbitm. It's this that has been confusing me and also does salesforce determine what the key is on it's own or do i have to define it?
    – Jsjjharp
    Commented Jul 28, 2016 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .