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 

APEX: Convert array to sql query

Hi, I am at a loss of words for how dumb I feel asking this simple question. I have an array of product Id's in list form:

 

[01t700000017VVBAA2, 01t700000017VVBAA2, 01t300000000OIDAA2, 01t70000002KgcDAAS]

 

That comes out when I print the list:

 

List<Product2> returnProducts = new List<Product2>();

 

using this visual force code:

 

<apex:outputText value="{!Products}" />

 

How do I convert returnProducts into a list of products.. because right now i just have their ID's

 

aka, I want to be able to pull stuff in visual force like

 

<apex:outputText value="{!Products.Name}" />


<apex:outputText value="{!Products.Id}" />

 

Stuff like that?

Best Answer chosen by Admin (Salesforce Developers) 
OyeCodeOyeCode

Try adding those changes, let us know if this works of follow up couple of threads dealing sames issues

 

All Answers

OyeCodeOyeCode

Little confused with your question but here is something of help

 

 <apex:outputLink value="/{!Product.Id}">{!Product.Name}</apex:outputLink>
Glen.ax1034Glen.ax1034

The error I am getting when I do the .Id:

 

<apex:outputText value="{!Products.Id}" />

 

:for example errors below:

 

Error: Unknown property 'VisualforceArrayList.Id'

Glen.ax1034Glen.ax1034
public class packageextensions {
    private final Packages__c PackageObj;
    public packageextensions (ApexPages.StandardController controller) {
        this.PackageObj= (Packages__c)controller.getSubject();
    }
    
    public List<Product2> getProducts() {
        //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]);
        
        }
        
        //List<Product2> productitem2 = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
        
        return returnProducts;
        
        }
        
    public List<String> getName() {
        //options.add(new Product2('None'));
    
        List<String> returnName = new List<String>();
        
        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];
              
            returnName.add(productitem[0].Name);
        
        }
        
        return returnName;
        
        }
        
}

 

 

 

 

<apex:page standardController="Packages__c" extensions="packageextensions">

    <table border="0" >

        <tr>

            <th>Case Number</th><th>Origin</th>

            <th>Creator Email</th><th>Status</th>

        </tr>

        <apex:repeat value="{!Products}" var="Nam">

        <tr>

            <td>{!Nam}</td>

            <td>test1</td>

            <td>test2</td>

            <td>test3</td>

        </tr>

        </apex:repeat> 

    </table>

<apex:outputText value="{!Products.Id}" />

</apex:page>

 

OyeCodeOyeCode

Suggest line number for the error

 

Try this

 

 <apex:repeat value="{!Products.Name}" var="Nam">

 

 

 

OyeCodeOyeCode

<apex:repeat value="{0}" var="Nam"> <apex:param value="{!Products.Name}" /> </apex:outputText>

 

Glen.ax1034Glen.ax1034


Error: Formula expression is required for attribute value in <apex:repeat> in TestSelect at line 19 column 38

 

<apex:page standardController="Packages__c" extensions="packageextensions">

    <table border="0" >

        <tr>

            <th>Case Number</th><th>Origin</th>

            <th>Creator Email</th><th>Status</th>

        </tr>

        <apex:repeat value="{!Products}" var="Nam">

        <tr>

            <td>
            
            <apex:repeat value="{0}">
            <apex:param value="{!Products.Name} />
            </apex:repeat>
            
            {!Products}</td>

            <td>test1</td>

            <td>test2</td>

            <td>test3</td>

        </tr>

        </apex:repeat> 

    </table>

<apex:outputText value="{!Products.Id}" />

</apex:page>

 

 

OyeCodeOyeCode
<apex:repeat value="Products.Name">
OyeCodeOyeCode

Retry this, though I remember this has been dealt before and couple of other people own the same issue, follow up this thread I believe

 

 

http://boards.developerforce.com/t5/forums/forumtopicprintpage/board-id/Visualforce/message-id/38389/print-single-message/false/page/1

OyeCodeOyeCode

You are quoting it again wrong I believe, let try to correct this

 

 <tr>

            <td>
            
            <apex:repeat value="{0}">
            <apex:param value="{!Products.Name} />
            </apex:repeat>
            
            {!Products}</td>      <- this should {!Products.Name} you can't right refer the whole list
 <td>test1</td> <td>test2</td> <td>test3</td> </tr>
OyeCodeOyeCode

Try adding those changes, let us know if this works of follow up couple of threads dealing sames issues

 

This was selected as the best answer
Glen.ax1034Glen.ax1034

still failing. i think it's the way i'm building the class or products2 list... 

 

perhaps you might be assuming that i have any clue what i am doing. I don't have any idea what i'm doing. lol

 

I think the error is somewhere here:

 

       productitem = [Select Name, Id from Product2 where id=:pbe[0].Product2Id];
              
            returnName.add(productitem[0].Name);
        
        }
        
        return returnName;

 

Glen.ax1034Glen.ax1034

Glen.ax1034Glen.ax1034

change:

Glen.ax1034Glen.ax1034

Glen.ax1034Glen.ax1034

Glen.ax1034Glen.ax1034

I don't know what happened but it works now.