function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Glen.ax1034Glen.ax1034 

Schema.SObjectField

I can't seem to figure out why I can't get this code to pull the Name of the product?

 

public class packageextensions {
    private final Packages__c PackageObj;
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
    }
    
    public List<Product2> getgProducts() {
        //options.add(new Product2('None'));
    
        List<Product2> returnProducts = new List<Product2>();
        
        List<Packages__c> origPackage = new List<Packages__c>();
        origPackage = [select Opportunity__c from Packages__c where id=:PackageObj.Id Limit 1];
        
        List<OpportunityLineItem> origOpportunityLineItem = new List<OpportunityLineItem >();
        origOpportunityLineItem = [Select PricebookEntryId from OpportunityLineItem where OpportunityId =:origPackage[0].Opportunity__c];
        
        
        for(OpportunityLineItem presentopp : origOpportunityLineItem) {
            List<PricebookEntry> pbe = new List<PricebookEntry>();
            pbe = [Select Product2Id from PricebookEntry where id=:presentopp.PricebookEntryId];
            
            List<Product2> productitem = new List<Product2>();
            
            productitem = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
            returnProducts.add(productitem[0]);
            debug.print(productitem[0].Name);
            //I CAN'T SEEM TO GET TO THE SUBCOMPONENTS FROM THE QUERY 3 Lines Above!
        
        }
        
        //List<Product2> productitem2 = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
        
        return returnProducts;
        
        }
              
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,


Use system.debug instead of debug.print;

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.