I have standard object(product) and a custom object (asset_line_item__c) and its a lookup relationship

my custom object has field called: quantity

my standard object has field called: product id, product name etc...

on the visualforce page i have to show:

quantity | product name | product type ....

for that reason I ended-up creating wrapper class:

public wrapperClass 
  public Integer quantity {get;set;}
  public Product2 product {get;set;}

  public wrapperClass(Product2 p){
      product = p;

this is how i'm updating the wrapperClass

for(product2 p : [select id,name,... from product2]) {
   Product2 pro = (Product2)p;
   wrapperClass wc = new wrapperClass(pro);            

in the Visualforce page:

  <apex:pageBlockTable value="{!prods}" var="a">                     
          <apex:column headerValue="Name" >
            <div class="requiredInput">
                <div class="requiredBlock"></div>
                <apex:inputText value="{!a.quantity}" required="true" />                    

I'm sure I just need little bit of tweak to make it better than what I have. so I can use inputField instead of inputText which is giving me a headache :)


Use your custom object strategically if you are not going to perform DML on it you can still use the fields...

public wrapperClass 

  public Product2 product {get;set;}
  public Asset_Line_Item__c ali {get;set;}

  public wrapperClass(Product2 p){
      product = p;
      ali = New Asset_Line_Item__c();

 public Integer quantity{
       return ali.Quantity__c == null ? 0 : integer.valueOf(ali.Quantity__c);


Then in your VF page use:

<apex:inputField value="{!a.ali.Quantity__c}" required="true"/>

You could use any object that contains a numerical field you need for the Quantity field.

While you are at it if you can use the ali object to perform your updates elsewhere may be no need for the additional integer property

  • Error: Compile Error: unexpected token: 'return' where we have this line of code return ali.Quantity__c == null ? 0 : integer.valueOf(ali.Quantity__c); – Nick Kahn Sep 15 '16 at 3:00
  • @NickKahn - Updated. forgot the get,set – Eric Sep 15 '16 at 3:01
  • ah ha silly me... i think i'm half sleep now – Nick Kahn Sep 15 '16 at 3:04

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.