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
Cory MitchellCory 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)

Best Answer chosen by Cory Mitchell
SubratSubrat (Salesforce Developers) 
Hello Cory ,

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. 
<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>
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

SubratSubrat (Salesforce Developers) 
Hello Cory ,

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. 
<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>
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.
This was selected as the best answer
Cory MitchellCory Mitchell
It helped alot, greatly appreciate it... Would you also have a code that would align this text to top? with a height of 14px?
Arun Kumar 1141Arun Kumar 1141
Hi @Cory

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.
 
<apex:page standardController="PricebookEntry" recordSetVar="pbe" label="Wholesale Price">
    <apex:repeat value="{!pbe}" var="entry">
        <apex:outputField rendered="{!entry.Product2.Name == 'Wholesale'}" value="{!entry.UnitPrice}" />
    </apex:repeat>
</apex:page>



Please mark it as Best Answer, if the above information was helpful for you.

Thanks
Cory MitchellCory Mitchell

@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.

Scaifez achariahScaifez achariah
he error you're experiencing is likely due to incorrect syntax in your Visualforce page. The rendered attribute of the <apex:outputField> tag expects a Boolean value to determine whether the field should be rendered or not. However, in your code, you're passing {!entry.Pricebook2.Name.Wholesale} to the rendered attribute, which is likely causing the error.
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/)