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
mramaprasad.ax1826mramaprasad.ax1826 

Customizing opportunity product detail page

I have added 3 products to an opportunity.When I try to edit the product (opportunity product detail), I need to show differnt fields based on the the the products I am editing. Since I can not create record types for opportunity product I want to write a visualforce page.

Can I achive this by creating a custom class and a visualforce page?
 
Jason Reiber [ACS]Jason Reiber [ACS]
You could create the VF page but the challenge would be how to link it to the related list for the Products on the Opportunity.  I can't find any way to change the behavior of the link on the items in that list, so I'm not sure how you'd tell it to navigate there.
mramaprasad.ax1826mramaprasad.ax1826
Can we not add a  button (may be next to the product name in the opportunity product list) which takes you to the VF page?

I am new to developemnt in SF. I am not sure how the whole thing works.

Thanks
Malini
mramaprasad.ax1826mramaprasad.ax1826
I basically need to achive  -  create multiple page layouts under OPPORTUNITY PRODUCTS. How do I use those page layouts? When I create an opportunity, add products and when I click on the product type I need to show different fields based on product type. Any suggestions? 
Jason Reiber [ACS]Jason Reiber [ACS]
Malini,

I understand your requirement, I'm just not sure there is a good way to accomplish it.  You can add a custom button to the related list, but it wouldn't be for a specific item in the list.  For example, you could have a button on the Products related list but you can't have a separate button next to each item in the Products related list that will let you navigate to a VF page specifically for that item.

Depending on what fields you want to add for the type of product you could just include them all in one layout and separate product specific fields with labels that notify the user that the field is only relevant for that particular product.

Alternatively you could add a custom button or link to the Opportunity Product Detail Layout that might be labeled something like "More Product Specific Details" where it could navigate to a VF page specifically for that Opportunity Product.  It's not ideal in terms of usability flow but it kind of depends which you prefer : all of the fields on one layout or having the user click another button to go to another VF page.
mramaprasad.ax1826mramaprasad.ax1826
We don't have too  many fields.

I was thinking
1) have a VF page which lists fields that are common to all produts.
2) Have If condition to check the product type and display specific fields. 
3) have the button next to each product name which takes you to the VF page that I created. Or I like your solution of adding it on the detail page as well.

But not sure how to go about doing it oe if it is even possible?
Jason Reiber [ACS]Jason Reiber [ACS]
Really you have 2 problems to solve :

1.) Finding a way to link the VF page to a single Product
2.) Building the VF page to dynamically show fields based on the specific Product

# 2 is easy, just use the "rendered" attribute of the pageblock element refer to some variables in your controller.  For example, you'd have boolean variables such as isProductA, isProductB and so on which are calculated in the Apex controller.  Then you just add all of your fields to the VF page and for the dynamic fields include the rendered attribute (i.e. rendered="{!isProductA}" would only display that element if isProductA is true)

#1 is the sticky part because you'll have to do something sub optimal to make it work.  The best way I can think of is my earlier suggestion of putting the custom link/button on the Opportunity Product Detail page layout.  The button would navigate to the VF page and can pass the appropriate variable values in the URL which the apex controller can then parse to determine which sections of the VF page will render.
mramaprasad.ax1826mramaprasad.ax1826
If I want to achive 
Depending on what fields you want to add for the type of product you could just include them all in one layout and separate product specific fields with labels that notify the user that the field is only relevant for that particular product.

How will add the button so that it opens my VF page?

 
mramaprasad.ax1826mramaprasad.ax1826
Thanks for your reply.
Currently (out of the box) when you click on the product name, it takes us to the product detail page. Can we not change so that we go to VF page?
Jason Reiber [ACS]Jason Reiber [ACS]
That's what I'm saying, I don't think you can change the native behavior of the product name link.  If you could, this whole thing would be a whole lot easier!  It's possible I'm wrong though and there is some neat trick that I'm unaware of to do this.
Jason Reiber [ACS]Jason Reiber [ACS]
You're in luck, I did some more digging and found this : http://www.salesforce.com/docs/developer/pages/Content/pages_quick_start_tabs.htm

You should be able to override the View function for the Opportunity Product object with a VF page.  That solves the second half of the problem
mramaprasad.ax1826mramaprasad.ax1826
Thank you so much for your time. Really appretiate it.

I created a class:

public class overrideCon{
      public void save() {
     }     
   }

I created a VF page (trainingProductPage):

<apex:page controller="overrideCon" action="{!save}"> <apex:detail /> </apex:page>

I am not able to see the page I created when trying to override View button under opportunity products. Any ideas what I am going wrong? 
 
mramaprasad.ax1826mramaprasad.ax1826
The I follwed the below steps to access:
   Go to Setup | Administration Setup | Manage Users | Profiles
Click on the profile label 
Scroll to the bottom and click edit for "Enabled Visualforce Page Access". 
Add the visual force pages 
Click save
mramaprasad.ax1826mramaprasad.ax1826
I was ale to override the view button. I have the following  code in visual force page:
<apex:page standardController="OpportunityLineItem">
   <apex:pageBlock id="xxxpb1">
    default product field
    <apex:pageBlockSection id="xxxpbs2" rendered="{!Product2Id== 'B01t17000000BmMT'}">
    product A  fields
    </apex:pageBlockSection>
 
   </apex:PageBlock>
</apex:page>

 I get the following error while saving.

Error: Unknown property 'OpportunityLineItemStandardController.Product2Id'

What am I doing wrong?
Jason Reiber [ACS]Jason Reiber [ACS]
Based on this documentation : https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_opportunitylineitem.htm  the Product2Id field was deprecated after API version 30.0.  The description says it just became read-only but maybe they've also disabled it in the mean time, it also says to use the PriceBookEntryId field instead.  Maybe that will solve your problem.
mramaprasad.ax1826mramaprasad.ax1826
Hello Jason,

I got that working. Here is what I have on my page:

<apex:page standardController="OpportunityLineItem" extensions="overrideCon" sidebar="true" showHeader="true">
<apex:form >
<input value=" Save " class="btn"  title="Save" name="save" type="submit"/>
<input value="Cancel" class="btn" title="Cancel" name="cancel" type="submit"/>
<apex:pageBlock id="xxxpb1">

Opportunity:&nbsp;&nbsp;{!opp.name}<br></br>
Product:&nbsp;&nbsp;{!pro.name}
Quantity: <apex:inputField value="{!OpportunityLineItem.Quantity}"/>
<apex:pageBlockSection id="xxxpbs2" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BmMdAAK'}">
    
   product 1 fields
    
    </apex:pageBlockSection>
    
    <apex:pageBlockSection id="xxxpbs3" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BmMTAA0'}">
    
    product 2 fields
    </apex:pageBlockSection>
    <apex:pageBlockSection id="xxxpbs4" rendered="{!OpportunityLineItem.Product2Id=='01t17000000BX9SAAW'}">
    
    product 3 fields
    </apex:pageBlockSection> 
</apex:pageBlock>
</apex:form>  
</apex:page>

How can I get the save and cancel button to save the changes?
mramaprasad.ax1826mramaprasad.ax1826
I should either call Save method or add form action. Not sure how to get that working?
mramaprasad.ax1826mramaprasad.ax1826
Modifying  to 
<apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/> 

worked.