• SGrabo_Nutricia
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

I'm a newbie to VF, so please be gentle...

 

I'm attempting to have a dropdown SelectList presented in a PageBlockTable so that adding new mass-insert records can be typified by a value drawn from another table. 

 

I have a simple custom object (Details) with only two editable fields: quantity and product ID. The product ID is to be drawn from a dropdown built from the Product2 table. I'd like to have the ID value of the product bound to the Details.ProductID__c value. This should be done in-line with the entry of the quantity, but I can't get the product SelectList to appear within the PageBlockTable.

 

My Apex:

 

<apex:page controller="DetailTesting"> <apex:form > <apex:PageBlock title="Products with a product type of 'Product'" tabstyle="Product2"> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!save}" rerender="error"/> </apex:pageBlockButtons> <b>Products</b><apex:selectList value="{!productList}" size="1"> <apex:selectOptions value="{!lowProteinProducts}"/> </apex:selectList> <apex:pageBlockTable value="{!sampleLowProtein}" var="a" id="table"> <apex:facet name="footer"> <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error"/> </apex:facet> <apex:column headerValue="Quantity"> <apex:inputField value="{!a.Quantity__c}"/> </apex:column> <apex:column headerValue="Name"> <apex:inputField value="{!a.Name}"/> </apex:column> </apex:pageBlockTable> </apex:PageBlock> </apex:form> </apex:page>

And my controller:

 

public class DetailTesting{ public String family; public List<Product2> productList = [select id, name, family from product2 order by name]; public List<Sample_Detail__c> sampleLowProtein{get; set;} public DetailTesting(){ sampleLowProtein = new List<Sample_Detail__c>(); sampleLowProtein.add(new Sample_Detail__c()); } public List<SelectOption> getLowProteinProducts(){ List<SelectOption> lowProteinProducts = new List<SelectOption>(); for (Integer i=0; i < productList.size() ; i++){ if (productList.get(i).family == 'Low Protein') lowProteinProducts.add(new SelectOption(productList.get(i).Id, productList.get(i).Name)); } return lowProteinProducts; } public void addRow(){ sampleLowProtein.add(new Sample_Detail__c()); } public PageReference save(){ insert sampleLowProtein; PageReference home = new PageReference('/home/home.jsp'); home.setRedirect(true); return home; } public List<Product2> getProductList() {return productList;} public void setProductList(List<Product2> productList) {this.productList = productList;} }

When I attempt to put LowProteinProducts inside the PageBlockTable, it does not appear. I assume this is because the PageBlockTable value is "{!sampleLowProtein}" while the SelectList value is "{!productList}".

 

I'm sure there's something obvious I'm missing, but help is clearly needed. How can I work around this?

 

 

 

 

I'm a newbie to VF, so please be gentle...

 

I'm attempting to have a dropdown SelectList presented in a PageBlockTable so that adding new mass-insert records can be typified by a value drawn from another table. 

 

I have a simple custom object (Details) with only two editable fields: quantity and product ID. The product ID is to be drawn from a dropdown built from the Product2 table. I'd like to have the ID value of the product bound to the Details.ProductID__c value. This should be done in-line with the entry of the quantity, but I can't get the product SelectList to appear within the PageBlockTable.

 

My Apex:

 

<apex:page controller="DetailTesting"> <apex:form > <apex:PageBlock title="Products with a product type of 'Product'" tabstyle="Product2"> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!save}" rerender="error"/> </apex:pageBlockButtons> <b>Products</b><apex:selectList value="{!productList}" size="1"> <apex:selectOptions value="{!lowProteinProducts}"/> </apex:selectList> <apex:pageBlockTable value="{!sampleLowProtein}" var="a" id="table"> <apex:facet name="footer"> <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error"/> </apex:facet> <apex:column headerValue="Quantity"> <apex:inputField value="{!a.Quantity__c}"/> </apex:column> <apex:column headerValue="Name"> <apex:inputField value="{!a.Name}"/> </apex:column> </apex:pageBlockTable> </apex:PageBlock> </apex:form> </apex:page>

And my controller:

 

public class DetailTesting{ public String family; public List<Product2> productList = [select id, name, family from product2 order by name]; public List<Sample_Detail__c> sampleLowProtein{get; set;} public DetailTesting(){ sampleLowProtein = new List<Sample_Detail__c>(); sampleLowProtein.add(new Sample_Detail__c()); } public List<SelectOption> getLowProteinProducts(){ List<SelectOption> lowProteinProducts = new List<SelectOption>(); for (Integer i=0; i < productList.size() ; i++){ if (productList.get(i).family == 'Low Protein') lowProteinProducts.add(new SelectOption(productList.get(i).Id, productList.get(i).Name)); } return lowProteinProducts; } public void addRow(){ sampleLowProtein.add(new Sample_Detail__c()); } public PageReference save(){ insert sampleLowProtein; PageReference home = new PageReference('/home/home.jsp'); home.setRedirect(true); return home; } public List<Product2> getProductList() {return productList;} public void setProductList(List<Product2> productList) {this.productList = productList;} }

When I attempt to put LowProteinProducts inside the PageBlockTable, it does not appear. I assume this is because the PageBlockTable value is "{!sampleLowProtein}" while the SelectList value is "{!productList}".

 

I'm sure there's something obvious I'm missing, but help is clearly needed. How can I work around this?

 

 

 

 

I have a custom object called "Overrides".  I've been developing a VisualForce page and custom controller that would allow users to data enter as many rows that they want of Overrides objects, at one time -- basically set them all up before clicking "Save".  On save each Overrides object row is saved.  This all works just as I want.

Now I need to add RecordTypes into the mix.  Ideally I want to have a dropdown at the top of the page where they will choose the record type of all of the Overrides objects they are creating for this particular "Save" operation.  I'm new to Apex and am having a hard time figuring this out.

Can someone show some sample code how to:

1) setup the controller to populate the RecordType dropdown box
2) set the dropdown box RecordType selection to each Overrides object when saving

Here is my controller:

Code:
public class multiOverrideInsertController{ 
      
    public List<Override__c> over{get; set;}   
    
    public multiOverrideInsertController(){        
        over= new List<Override__c>();        
        over.add(new Override__c());    
    }        

    public void addrow(){        
        over.add(new Override__c());    
    }     
    
    public void removerow(){  
        Integer i = over.size();      
        over.remove(i-1);    
    }        

    public PageReference save(){       
        insert over;        
        PageReference home = new PageReference('/a00/o');        
        home.setRedirect(true);        
        return home;    
    }
}

Here's my VisualForce page:

Code:
<apex:page controller="multiOverrideInsertController">    
    <apex:form >        
    <apex:pageBlock title="Insert Multiple Overrides">                    
        <apex:pageBlockButtons >                
            <apex:commandButton value="Save" action="{!save}" rerender="error,table"/>            
        </apex:pageBlockButtons>                    
        <apex:pageMessages ></apex:pageMessages>
    <apex:pageBlockTable value="{!over}" var="a" id="table">      
        <apex:column headerValue="Opportunity">                    
            <apex:inputField value="{!a.Opportunity__c}" required="true" />                         
        </apex:column>     
        <apex:column headerValue="Institution">                    
            <apex:inputField value="{!a.Institution__c}" required="true" />                         
        </apex:column> 
        <apex:column headerValue="Advisor (Rep)">                    
            <apex:inputField value="{!a.Advisor_Rep__c}" required="true" />                         
        </apex:column>                              
        <apex:column headerValue="Override Date">                      
            <apex:inputField value="{!a.Override_Date__c}" required="true" />                          
        </apex:column>
        <apex:column headerValue="Override Amount">                    
            <apex:inputField value="{!a.Override_Amount__c}" required="true" />                           
        </apex:column>                                          
     </apex:pageBlockTable>   
     <apex:pageblockButtons location="bottom">   
         <div style="text-align:right;margin-right:30px;font-weight:bold;">             
            <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error" immediate="true" /> &nbsp;|&nbsp;&nbsp;  
            <apex:commandLink id="RemoveRow" value="Remove Row" action="{!removeRow}" rerender="table,error" immediate="true" />
         </div>      
     </apex:pageblockButtons>                      
    </apex:pageBlock>    
    </apex:form>
</apex:page>