You need to sign in to do that
Don't have an account?
Cory Mitchell
Pricebook entry to product layout
I'm currently running this code to try and put my pricebook into my product layout page.
I need to run create three seperate vidual force pages for Wholesale, Promo Direct and Promo Distributor.
What am i missing?
<apex:page standardController="Product2" label="Wholesale Price">
<apex:repeat value="{!Product2.PricebookEntries}" var="entry">
<apex:outputField rendered="{!entry.Pricebook2.Name.Wholesale}" value="{!entry.UnitPrice}" />
</apex:repeat>
</apex:page>
I'm getting an error at this line of code. (Underlined and italics)
The error you're encountering is likely due to accessing the Name field on the Pricebook2 object in the Visualforce page. To fix this, you should directly compare the Name field value to the desired value (e.g., "Wholesale") rather than accessing the Name field itself. In the updated code, the rendered attribute of the apex:outputField component uses the expression {!entry.Pricebook2.Name == 'Wholesale'} to compare the Name field value with the string 'Wholesale'. This will render the apex:outputField only if the Name field of the related Pricebook2 object is equal to "Wholesale".
Make sure to replicate this approach for your other Visualforce pages for "Promo Direct" and "Promo Distributor", modifying the comparison string accordingly.
If this helps , please mark this as Best Answer.
Thank you.
All Answers
The error you're encountering is likely due to accessing the Name field on the Pricebook2 object in the Visualforce page. To fix this, you should directly compare the Name field value to the desired value (e.g., "Wholesale") rather than accessing the Name field itself. In the updated code, the rendered attribute of the apex:outputField component uses the expression {!entry.Pricebook2.Name == 'Wholesale'} to compare the Name field value with the string 'Wholesale'. This will render the apex:outputField only if the Name field of the related Pricebook2 object is equal to "Wholesale".
Make sure to replicate this approach for your other Visualforce pages for "Promo Direct" and "Promo Distributor", modifying the comparison string accordingly.
If this helps , please mark this as Best Answer.
Thank you.
PricebookEntry is a Child object of the Product, you must use it as a standardController because we are unable to use the name with the dote directly in rerendered. In order to compare the product name, we require an equal operator.
Try this code, and hope it meets your requirement.
Please mark it as Best Answer, if the above information was helpful for you.
Thanks
@arun,
I utilized @subrat solution and it worked, im just looking into aligning text to the top of field at this point. I thank you for your code as well. I will hold on to that if any other issue arises.
To fix this issue, you need to modify your code to provide a valid Boolean expression for the rendered attribute. Here's an example assuming Wholesale is a field on Pricebook2:
<apex:page standardController="Product2" label="Wholesale Price">
<apex:repeat value="{!Product2.PricebookEntries}" var="entry">
<apex:outputField rendered="{!entry.Pricebook2.Wholesale}" value="{!entry.UnitPrice}" />
</apex:repeat>
</apex:page>
Make sure that the field Wholesale exists on the Pricebook2 object and is of the Boolean type. Additionally, ensure that you have the necessary access permissions to the fields and objects referenced in your Visualforce page hoopese (https://hoopese.com/)