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

Controller: 
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
    {get;set;}  
    
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    //{get;set;}
    
    
    ////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++)
        {
            lstRevRec.add(lstInner[j].revrec);
        } 
        insert lstRevRec;
        pr.setRedirect(True);
        return pr;
    }
        
    //add one more row
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    
    /*Begin addMore*/
    public void addMore()
    {
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        
        //add the record to the inner class list
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }/* end addMore*/
    
    /* begin delete */
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }/*End del*/
    
    
    
    /*Constructor*/
    public revRecMultiadd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        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
        {get;set;}
        
        
        public Revenue_Recognition__c revrec
        {get;set;}
        
        /*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:pageBlockButtons>
    
        
        <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:commandButton>
                </apex:panelGrid>   
                
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Duration</apex:facet>
                    <apex:inputfield value="{!Revenue_Recognition__c.Duration__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Start Date</apex:facet>
                    <apex:inputfield value="{!Revenue_Recognition__c.Start_Date_Delivery_Date__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:inputfield value="{!Revenue_Recognition__c.Name}"/>
                </apex:panelGrid>
            </apex:panelgrid>
        </apex:repeat>
    </apex:pageBlock>
        
</apex:pageblock>
</apex:form>
</apex:page>

Any help is highly apprecitated!! 

Thanks so much,
Heather
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.

Thanks
Nitin
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."

Thanks!!
Heather
 
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.

Thanks
NItin

 
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