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
BerettaJonBerettaJon 

Having trouble making an APEX call from my VF page.

Hi devs!

 

VF page uses 

<apex:repeat value="{!optionRows}" var="opRow">

To display info.  To be honest I am not sure what/where/how this opRow object is populated.

Nevertheless the opRow var here contains a field that is the same as a Product name.

 

I am trying to return a feild off of the Product record that is related to the opRow var by product name(as you can see in the SOQL in the apex).

 

Here are some code snippets showing how I tried to do this.  The code below is most defiantly not correct and may or may not be helpful.  Please let me know if any additonal info is required in order to help me.  

 

The person who provides an answer will be eligible for a 0.01 BTC reward if you are interested :)

 

 

<APEX CODE>

public OptionRow2 OpRow{get;set;}
    public Product2 getProductFromOpRow()
    {
        
            if(OpRow.dropdownname == null)
            {
                myProduct = [select Product_Image_URL__c from Product2 where name = :OpRow.CheckBoxName];
            }
            if(OpRow.CheckBoxName == null)
            {
                myProduct = [select Product_Image_URL__c from Product2 where name = :OpRow.dropdownname];    
            }
            return myProduct;
       
    }

</APEX CODE>

 

 

<VF CODE>

<div class="image">
<apex:repeat value="{!ProductFromOpRow}" var="opRowP">
<apex:image url="!opRowP.Product_Image_URL__c " rendered=
"{! if(opRowP.Product_Image_URL__c != null && opRow.isDropDown == false,true,false)}" /> </apex:repeat> </div>

 

 

</VF CODE>

 

 

Hengky IlawanHengky Ilawan

Hi Beretta,

 

There are some glitches in your VF page:

- apex:repeat value attribute takes a collection of object, but your getProductFromOpRow() doesn't return a collection.

- there is no SRC attribute in apex:image, you should use Value attribute instead of SRC

- you can't use apex syntax in VF page, use functions instead.

 

<div class="image">
    <apex:repeat value="{!ProductFromOpRow}" var="opRowP">
        <apex:image value="{!opRowP.Product_Image_URL__c}" rendered="{!
         AND(
           NOT ISNULL(opRowP.Product_Image_URL__c),
           NOT(opRow.isDropDown)
         )}" />
    </apex:repeat>
</div> 

 

Some references:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_repeat.htm

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_image.htm

http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_functions.htm

 

Regards,

Hengky

BerettaJonBerettaJon

OK I agree with all of your suggestions.  Thanks!

 

I am getting an error now right after I call the apex.  I don't think I am passing my OpRow object to the apex from the VF because the error occurs at the very first reference to the OpRow object in my Apex method.

 

Thanks

8:23:53.945 (2945607000)|CODE_UNIT_STARTED|[EXTERNAL]|01p600000000OmA|ProductConfiguratorController2 get(ProductFromOpRow)
08:23:53.945 (2945620000)|SYSTEM_MODE_ENTER|true
08:23:53.945 (2945634000)|CODE_UNIT_STARTED|[EXTERNAL]|01p600000000OmA|ProductConfiguratorController2 invoke(getProductFromOpRow)
08:23:53.945 (2945678000)|SYSTEM_MODE_ENTER|false
08:23:53.945 (2945709000)|METHOD_ENTRY|[13]|01p600000000OmA|ProductConfiguratorController2.__sfdc_OpRow()
08:23:53.945 (2945745000)|METHOD_EXIT|[13]|01p600000000OmA|ProductConfiguratorController2.__sfdc_OpRow()
08:23:53.945 (2945822000)|SYSTEM_MODE_EXIT|false
08:23:53.945 (2945924000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object