1

So for this is what i have and i have zero clue on how to continue. What i do know is the Product2 Id is what links to the arrays together, to end up displaying like so....and i have no idea exactly how to do that...I know both lists will have the same Product2 Id but beyond that i'm at a loss.

enter image description here

public class wrapperClass
{
    public integer price {get;set;}
    public integer quantity {get;set;}
    public Id productId {get;set;}
    public Id pbEntry {get;set;}
    public Id themeConversionId {get; set;}
    public Id parentOpp {get;set;}
    
    public wrapperClass(Theme_Conversion__c tc) {
        this.themeConversionId = tc.Id;
        this.price = tc.Min_or_Flat_Fee_Amount__c;
        this.quantity = tc.Quantity__c;
        this.productId = tc.To_Theme__r.Id;
        this.themeConversionId = tc.Id;
        this.parentOpp = tc.Sales_Toolkit__r.Opportunity_Name__r.Id;
    }
    public wrappperClass(PricebookEntry pbe){
        this.pbEntry = pbe.Id;
        this.productId= pbe.Product2Id;
    }
}

@AuraEnabled
public static boolean getParentOpp(string recordId){
    Theme_Conversion__c[] qli = getLineItems(recordId);
    PricebookEntry[] pbe = getPriceBookEntry(qli);
}

/**
 * retrieves line items 
 * @param recordId
 */
public static List<Theme_Conversion__c> getLineItems(string recordId){
    return  [ SELECT Id,Min_or_Flat_Fee_Amount__c,Quantity__c, Product2__r.Id, Sales_Toolkit__r.Opportunity_Name__r.Id 
              FROM Theme_Conversions__c 
              WHERE Sales_Toolkit__c =:recordId];
}

/**
 * retrives pricebookentries for related products
 * @param qli
 */
public static List<PricebookEntry> getPriceBookEntry(Theme_Conversion[] qli){
    Set<string> productIds = new Set<string>();
    
    for(Product2 p : qli){
        productIds.add(p.Product2__r.Id);
    }
    return [SELECT Id, Product2Id 
            FROM PricebookEntry 
            WHERE Product2Id =:productIds AND Pricebook2Id =:PRICEBOOK2_ID];
}
4

You declared

public Product2 product {get;set;}
public PricebookEntry pbEntry {get;set;}
public Theme_Conversion__c themeConversionId {get; set;}
public Opportunity parentOpp {get;set;}

But you're assinging an Id to those properties, so you should change their type:

public Id product {get;set;}
public Id pbEntry {get;set;}
public Id themeConversionId {get; set;}
public Id parentOpp {get;set;}

Even the signature of getPriceBookEntry is wrong: it returns a list of PricebookEntry, not a String, so It should be:
public static List<PricebookEntry> getPriceBookEntry(Theme_Conversion[] qli) {


In order to merge the two lists you need a Map. The key will be the common property, the Product2's Id, and the value will be a wrapper class instance. After retrieving the list of Theme_Conversion__c you can populate the map, then you can retrieve the list of PricebookEntry, loop over it and retrive the wrapper class from the map using Product2Id in order to set the missing field.
It is guaranteed that the key exists in the map, since you retrieved the PBE using the map's keySet.

@AuraEnabled
public static boolean getParentOpp(string recordId){
    Map<Id, WrapperClass> mapProductIdToWrapper = new Map<Id, WrapperClass>();
    Theme_Conversion__c[] qliList = getLineItems(recordId);
    for (Theme_Conversion__c qli : qliList) {
        WrapperClass wrapper = new WrapperClass(qli);
        mapProductIdToWrapper.put(wrapper.product, wrapper);
    }
    PricebookEntry[] pbeList = getPriceBookEntry(qliList);
    for (PricebookEntry pbe : pbeList) {
        mapProductIdToWrapper.get(pbe.Product2Id).pbEntry = pbe.Id;
    }
}

If getPriceBookEntry method is used only in this class, you can change its signature to
private static List<PricebookEntry> getPriceBookEntry(Set<Id> productIds) { then update its body accordingly. This way you can call it passing mapProductIdToWrapper.keySet()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.