Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Marketplace
    • Advertise With Us
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › How to create a vf page automatically on creation of Account?

    Tagged: Account, Salesforce Apex, Salesforce Visualforce Page, Tooling API

    • Salesforce® Discussions

      How to create a vf page automatically on creation of Account?

      Posted by Tanu on July 19, 2016 at 6:15 AM

      How to create a vf page automatically on creation of Account and show some related information on vf page ?

      Shekhar Gadewar replied 9 years, 6 months ago 4 Members · 5 Replies
      • Account
      • Salesforce Apex
      • Salesforce Visualforce Page
      • Tooling API
    • 5 Replies
    • Satyakam

      Member
      July 19, 2016 at 8:51 AM

      Hi,

      if you want to show another vf page after inserting an account,than you should use pagereference for another vf page and show all the details of account using <apex:outputText >.

    • Sourabh

      Member
      July 19, 2016 at 9:00 AM

      Hi Tanu,

      *For this you have to create a class using ApexTooling Api which create page dynamically. It can be done using REST Api callout used in Tooling Api.
      *After this you have to create a trigger which calls the class after insertion of Account.

      Thankyou

    • Shekhar Gadewar

      Member
      July 19, 2016 at 10:15 AM

      Thanks Sourabh for such useful info.

      Do you have any sample for that?

       

      Thanks

       

    • Sourabh

      Member
      July 19, 2016 at 1:06 PM

      Hi Shekhar,
      I am providing you an example of Dynamic Page creation using ApexTooling Api.

      *Here i have created a vf page in which the object name is entered(custom/standard) on entering object name in input field & clicking on 'create page', a page is been created dynamically refrencing to the object in StandardController.

      * Make sure you have put your base url in Remote Site Settings, It is needed for callout.

      Vf Page:-

      <apex:page controller="ctrl_DynamicPageCreation">
      <apex:form id="form1">

      <div style="margin-left: 23px;">
      <h1 style="padding-right: 10px;"> Object Name</h1>
      <apex:inputText html-placeholder="Object Name..." value="{!objectName}">
      </apex:inputText>
      </div> <br/>
      <apex:commandButton value="CreatePage" action="{!createpage}" reRender="Error" style="margin-left: 23px;"/>
      </apex:form>

      <apex:outputpanel id="Error">

      <apex:pageMessages ></apex:pageMessages>
      </apex:outputpanel>
      </apex:page>
      Controller:-

      public class ctrl_DynamicPageCreation{

      public String objectName{get;set;}
      Public String name;

      public ctrl_DynamicPageCreation(){}

      public void createpage(){

      if(objectName.contains('__c')){
      name = objectName.replace('__c','');
      }

      system.debug('****'+objectName);
      String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();

      String url = salesforceHost + '/services/data/v29.0/sobjects/ApexPage';

      HttpRequest req = new HttpRequest();

      req.setMethod('POST');
      req.setEndpoint(url);
      req.setHeader('Content-type', 'application/json');
      req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
      //for controllerType = >0 -- no controller
      //req.setBody('{"Name" : "TestPageFromRest","Markup" : "<apex:page>hello</apex:page>","ControllerType" : "0","MasterLabel":"TestPageFromRest","ApiVersion":"29.0"}');

      //for controllerType => 1 -- Standard controller + extensions
      req.setBody('{"Name" : "FileUploader'+name+'","Markup" : "<apex:page standardController=\''+objectName+'\' extensions=\'dynamicCreationController\'>hello</apex:page>","ControllerType" : "1","MasterLabel":"FileUploader'+objectName+'","ApiVersion":"29.0"}');

      //for controllerType => 3 --custom Controller
      //req.setBody('{"Name" : "DynamicPage'+objectName+'","Markup" : "<apex:page controller=\''+objectName+'\'>hello</apex:page>","ControllerType" : "3","MasterLabel":"TestPageFromRestCase23","ApiVersion":"29.0"}');
      Http http = new Http();

      HTTPResponse res = http.send(req);
      System.debug(res.getBody());
      if(string.valueof(res.getBody()).contains('success')){
      ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM,'Your Page has been created..');
      ApexPages.addMessage(myMsg);
      }
      else{
      string errorMessage = string.valueof(res.getBody());
      string test = errorMessage.substring(13,errorMessage.indexOf('","errorCode'));
      system.debug('&&&&'+test);
      if(test.contains('Markup')){
      ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Object does not exist. Please check the spelling and try again.');
      ApexPages.addMessage(myMsg);
      }

      else if(test.contains('That page name is already in use, please choose a different one.')){
      ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Page for this object is already been created. Try to choose different one.');
      ApexPages.addMessage(myMsg);
      }
      else{
      ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,test);
      ApexPages.addMessage(myMsg);
      }
      }
      }
      }

      Hope so this information is helpful to you.
      Thanks

    • Shekhar Gadewar

      Member
      July 21, 2016 at 1:10 PM

      Thanks a lot Saurabh!!

      🙂

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    application solution

    Popular Salesforce Blogs

    Supercharge Support Agents with These Lesser-Known Salesforce Service Cloud Features

    Blog in Salesforce, Salesforce Cloud Platform

    We are living in a time when customer experience matters the most for a business. A disappointed customer will take no longer a minute to…

    Business, Case Resolution, Centralized Data, Customer, Customer Experience
    360 Degree May 9, 2022
    2,182  Views

    Salesforce Lightning Experience: Main Reasons Why Salesforce Classic is Fading

    Blog in Others

    Introduction "Salesforce Classic is at its Death-End and s going to be okay!" These things are creating a buzz in the online Salesforce Lightning world.…

    App Launcher, Back-end Integration, Business Enterprises, Classic Platform, Classic to Lightning
    Emorphis Jul 6, 2020
    7,404  Views

    Salesforce Launched Marketing Cloud For Nonprofits

    Blog in Salesforce, Salesforce Cloud Platform

    Recently, Salesforce introduced Marketing Cloud for Nonprofits to assist them in creating more personalized experiences for their donors quickly and efficiently, regardless of where they…

    AppExchange, Audience Interaction, Campaign Performance, Constituent Engagement Strategies, Crowdfunding Tool
    Apphienz Aug 3, 2021
    1,848  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.