5

I created a Visualforce component that I'd like to add to a few page layouts, but it seems that the controller only allows for it to be on one object.

Is there any way to create the component so that it can be added to any page layout?

Here's what I have so far:

<apex:page >
    <!-- Replace parentId attribute with Id of an object that supports attachments --><br/>
    <c:fileUpload parentId="{!$CurrentPage.parameters.id}" />     
</apex:page>
7

A VisualForce page can only be added to an object's Page Layout if it declares the standardController attribute and its type must match.

<apex:page standardController="MyObject__c>
    <c:fileUpload....
</apex:page>

I don't think there's any workaround for this

The other alternative is to declare a new Home Page Component -- it would appear on every page, but you can put an VF page in an IFRAME in the component and from within the VF Controller, you can do some clever discovery using the Referer header to figure out what type of object you're looking at. (using the id parameter and getGlobalDescribe to wander through to figure out the object type you're looking at based on the key prefix)

<?xml version="1.0" encoding="UTF-8"?>
<HomePageComponent xmlns="http://soap.sforce.com/2006/04/metadata">
    <body>&lt;iframe style=&quot;display: inline;&quot; id=&quot;wiFrame&quot; marginheight=&quot;0&quot; border=&quot;0&quot; src=&quot;/apex/c__BobHome&quot; allowtransparency=&quot;&quot; name=&quot;wiFrame&quot; marginwidth=&quot;0&quot; width=&quot;100%&quot; frameborder=&quot;0&quot; height=&quot;250&quot;&gt;&lt;/iframe&gt;</body>
    <pageComponentType>htmlArea</pageComponentType>
    <width>narrow</width>
</HomePageComponent>
  • Fortunately, it's a matter of just copy-pasting new pages that use the same code with a different standardController. Takes maybe a minute per object, less if you're efficient on a fast network/computer. – sfdcfox Sep 16 '13 at 16:30
  • @sfdcfox So within a managed package, I would just have to send over different VF pages with the Standard Controllers for Standard Objects? – McD Oct 11 '13 at 16:30
  • @sfdcfox And how would this work with Custom Objects? Thanks! – McD Oct 11 '13 at 16:30
  • Assuming the component's access level is "global", it will work with any standard or custom object, even across multiple managed packages. There's some stigma using global elements, though, so be careful. It's difficult or impossible to change a component once it's made global (the system restricts changes so that future changes won't break previous implementations). This often leads to versioning components (e.g. myns:doSomething1, myns:doSomething2, etc). – sfdcfox Oct 11 '13 at 18:37
0

I managed to get around this by temporarily changing the custom one to a standard one, adding the page to the layout, and then reverting the changes. This allowed me to host the same VF page on multiple Object pages (Contact, Account, Lead). No issues so far, although the page only used the record Id and hosted a button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.