+ Start a Discussion
Heather BazelHeather Bazel 

Embed VF Custom Object into Standard Opp Page Layout

Hi all,

I need to embed my VF Custom Object into my Opportunity Page Layout, but not sure how to accomplish this. I know that the standardController points to the Custom Object, but how do I create a relationship with the Opportunity so that I am able to add it to the Opp Page Layouts? Below is my Controller and VF Code:

public class revRecMultiadd
    //will hold the rev rec records to be saved
    public List<Revenue_Recognition__c>lstRevRec  = new List<Revenue_Recognition__c>();
    //list of the inner class
    public List<innerClass> lstInner 
    {   get;set;    }
    //will indicate the row to be deleted
    public String selectedRowIndex
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    ////save the records by adding the elements in the inner class list to lstAcct,return to the same page
    public PageReference Save()
        PageReference pr = new PageReference('/apex/revRecMultiadd');
        for(Integer j = 0;j<lstInner.size();j++)
        insert lstRevRec;
        return pr;
    //add one more row
    public void Add()
        count = count+1;
    /*Begin addMore*/
    public void addMore()
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        //add the record to the inner class list
    }/* end addMore*/
    /* begin delete */
    public void Del()
        system.debug('selected row index---->'+selectedRowIndex);
        count = count - 1;
    }/*End del*/
    public revRecMultiadd(ApexPages.StandardController ctlr)
        lstInner = new List<innerClass>();
        selectedRowIndex = '0';
    }/*End Constructor*/

    /*Inner Class*/
    public class innerClass
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        public Revenue_Recognition__c revrec
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
            recCount = String.valueOf(intCount);        
            /*create a new account*/
            revrec = new Revenue_Recognition__c();
        }/*End Inner class Constructor*/    
    }/*End inner Class*/
}/*End Class*/

VF Code:
<apex:page StandardController="Revenue_Recognition__c" extensions="revRecMultiadd" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
        <apex:pageblock id="pb1">
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="5">
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Duration</apex:facet>
                    <apex:inputfield value="{!Revenue_Recognition__c.Duration__c}"/>
                <apex:panelGrid >
                    <apex:facet name="header">Start Date</apex:facet>
                    <apex:inputfield value="{!Revenue_Recognition__c.Start_Date_Delivery_Date__c}"/>
                <apex:panelGrid >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:inputfield value="{!Revenue_Recognition__c.Name}"/>

Any help is highly apprecitated!! 

Thanks so much,
Nitin PaliwalNitin Paliwal
Hi Heather,
In order to embed a custom vf page in the Standard Opportunity page layout, you need to make the standard controller of the page as "Opportunity" and not you custom object.
There should be lookup/master-detail relationship between Your custom object and Opportunity, opportunity being parent of your custom object.
In your visualforce page, where the standard controller is opportunity , query all the child records(Your custom object) records associated to the opportunity and show them on the page.

Heather BazelHeather Bazel
Hi Nitin,
My Custom Object does have a MD Relationship with the Opportunity. I swaped out the Custom Object with the Standard Object in the Controller, but now get this error:
Error: Unknown property 'OpportunityStandardController.Revenue_Recognition__c'

I think I am lost here:
"In your visualforce page, where the standard controller is opportunity , query all the child records(Your custom object) records associated to the opportunity and show them on the page."

Nitin PaliwalNitin Paliwal
Hi Heather,
By looking at the code , i realized that you are just inserting and deleting the records for the your custom object , right.
For this purpose, i dont find a need of the visualforce page design, you can add the related list of this object on the Opportunity Page layour, and use the native SFDC functionality.

Step 1- Setup->Customize->Opportunity->Page Layouts.
Step 2 - Edit a layout.
Step 3 - Goto the Related list section , and drop your Custom object in related list section.
Step 4 - Save the layout.
Step 5- On any opportunity record , you would find your custom object, and a new  button to insert records.

Let me know it fullfills your scenario, otherwise let me know the need of the vf page.


Heather BazelHeather Bazel
Hi Nitin, Right now yes that is all it does. I am not done with it quite yet, I am literally just learning how to do this today so just playing around with it and trying to learn. I do have a need where the users would like to have an inline editing component on the Opportunity for Revenue Recognition, so instead of creating new records on a CO Related List, they are just adding lines quickly and adding their data in those lines. Then once I get that, I need to figure out how to do some automation where if certain value is chosen in a picklist, it will automate the lines added and some currency and date calculations... but that is phase 2 since it will take me forever to learn it. :) Thanks!Heather