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
springdevspringdev 

Creating a managed package with optional VisualForce components

So here's my problem:

 

I have a VisualForce component that I want to be able to drop onto any page layout (Account, Contact, Opportunity, etc).  My component doesn't need anything except for an id and a type, so it can be used on page layout.

 

So I have this one VisualForce page.  I only need this one VF page, because as I said, generic code.  However, in order for it to show up in the layout for the page, I find that I need to have a different VisualForce page for each type, with <apex:page standardController="Account"> set appropriately on each page.

 

So now I have ~10 pages that are all the same except the value of the standardController attribute, but it works.

 

Now I package up my code, and I include all of these pages.  It deploys just fine to a full salesforce.com account.  However, if I try to deploy it to a force.com account (which has only Account and Contact, and doesn't have Lead, Opportunity, etc, etc) it fails because there are VisualForce pages that reference those types, but those types are not configured for that organization.

 

I don't particularly care -- I want them to be able to install anyway, even if they don't have those types.  But I simply cannot find a way to make this work.

 

So, my questions:

 

#1. Is this the proper way of adding a generic VisualForce page to any layout, or is there an easier way of doing it than creating a different copy per object type?

 

#2. Is there a way to add VisualForce pages to a package conditionally, or mark them as optional, or otherwise not fail to deploy to an organization that doesn't have all the types?

sfdcfoxsfdcfox

#1) Yes, the standardController attribute is required and can't be dynamic, so one page per is indeed required.

 

#2) Not directly, no, but what you can do is create your base package, install it in a new dev org, and then create a second package that depends on the first package. This second package can be managed or unmanaged to suit your needs. Alternatively, you csn just give the users a template, and tell them how to do it themselves (you can call managed code from unmanaged pages).