Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm wondering if there's a way to create a visualforce page that lists all the objects (standard & custom) in a Salesforce org and each to next object there is a button called "Create Page" which, when pressed, will create a Visualforce page with that object's controller?

Or could this be possible with a set of Triggers?

share|improve this question

Not natively - Apex and Visualforce do not have direct access to the MetaData API, so you would need to approach it similar to other API integrations. You might check out FinancialForce's apex-mdapi library:

share|improve this answer
Yep code sample is here...… – Andrew Fawcett Feb 25 '14 at 23:47

You can knock this out fairly simply by using the Ajax Toolkit within your visualforce page, which is capable of creating and updating visualforce via create and update calls. Here is an example of a page that updates itself, recoding the name of whomever visits it:

<apex:page showHeader="true" sidebar="true" title="???">

    <apex:includeScript value="/soap/ajax/25.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/25.0/apex.js"/>

        Who has visited this page so far:<br /><br />
        WHOSE NEXT?

        sforce.connection.sessionId = '{!$Api.Session_ID}';

        function printUsername(result) {
            result         = result.getArray('records');
            var next       = 'WHOSE NEXT?';
            var newName    = '{!$User.FirstName & " " & $User.LastName} <br/>' + next;

            result[0].Markup = result[0].Markup.replace(next, newName);

            "SELECT Id, Markup FROM ApexPage WHERE Name = 'Mystery'", 
            { onSuccess : printUsername });

share|improve this answer
Wait, Markup is editable on the ApexPage object? When did that happen? – drakored Feb 25 '14 at 23:39
Been that way for years. Just have to do it externally from salesforce (read: not from apex). SOQL Xplorer can be a visualforce ide if you really wanted it to. Works for Visualforce and Static resources, but no dice for Apex. – Phil Rymek Feb 25 '14 at 23:41
Which means this will probably work via SF REST API from Apex also I guess, nice. Spring'14 also brings with it a Metadata API update API that is synchronous – Andrew Fawcett Feb 25 '14 at 23:46
@PhilRymek - Nice, I seem to recall trying from anon apex, I bet that is why I assumed it was unwritable. – drakored Feb 26 '14 at 0:01
Thanks Phil! You mention it can update and create? I'm really looking for the ability to have a user select a subset of their Objects (standard and custom) for which they want a VF page created - would this functionality be able to then create those VF pages? – McD Feb 27 '14 at 0:21

If you want complete flexibility, you will have to go for metadata api. There is metadata API wrapper classes developed by financial force team. Details can be found in below link,

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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